AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 会员列表

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
       
Title: 翻页与循环输出程序,原来可以这样写。?,? 防注入。  
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3929
码币MB 2556 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status online
翻页与循环输出程序,原来可以这样写。?,? 防注入。



if ($_SERVER["REQUEST_METHOD"] == "POST") { foreach ($_POST as $field => $value) { // 更新记录中的每个字段 $updateQuery = "UPDATE atte2 SET $field = '$value' WHERE id = ?"; $stmt = $conn->prepare($updateQuery); $stmt->bind_param("i", $_POST['id']); $stmt->execute(); } } // 查询 "atten2" 表的数据 $page = isset($_GET['page']) ? intval($_GET['page']) : 1; $limit = 30; $offset = ($page - 1) * $limit; $selectQuery = "SELECT * FROM attedance2 LIMIT ?, ?"; $stmt = $conn->prepare($selectQuery); $stmt->bind_param("ii", $offset, $limit); $stmt->execute(); $result = $stmt->get_result(); // 输出表格并为每个字段创建输入框 echo '<form method="POST">'; echo '<table>'; while ($row = $result->fetch_assoc()) { echo '<tr>'; echo '<td><input type="hidden" name="id" value="' . $row['id'] . '">' . $row['id'] . '</td>'; echo '<td><input type="text" name="field1" value="' . $row['field1'] . '"></td>'; echo '<td><input type="text" name="field2" value="' . $row['field2'] . '"></td>'; // 继续为其他字段创建输入框... echo '</tr>'; }




CAFFZ.com
2023-7-7 12:32#1
View profile  Blog  Send a short message  Top
       


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2026-1-21 16:16 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE