AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 冻结用户(激活) | Residents

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
       
Title: 翻页与循环输出程序,原来可以这样写。?,? 防注入。  
  This topic was added by com at 2024-11-22 11:53 移动 
 
sky999
天山茗客



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



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 2025-6-27 15:00 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE