gpt4 book ai didi

php - 为每个用户在按钮点击时传递 ID

转载 作者:行者123 更新时间:2023-11-29 06:04:22 25 4
gpt4 key购买 nike

我想为每个数据库条目设置一个编辑按钮,当用户点击编辑时,它只会获得条目,就在它旁边。我试过使用像 <input type="hidden" name="userid" value=...> 这样的隐藏输入但我真的不知道把它放在哪里,也不知道它有什么用。

所以你也可以想象一下,我附上了一张 table 的照片。

enter image description here

我希望你能帮助我,如果你有任何其他信息需要知道,请告诉我。

<?php
include 'dbConnect.php';
echo '<table border="1" cellpadding="1" cellspacing="1" width="90%" style="margin: 0 auto">';
echo '<tr class="allUsers">';
echo '<th>Username</th>';
echo '<th>First name</th>';
echo '<th>Last name</th>';
echo '<th>Email</th>';
echo '<th>Year group</th>';
echo '<th>Subject 1</th>';
echo '<th>Subject 2</th>';
echo "<th>Subject 1's teacher</th>";
echo "<th>Subject 2's teacher</th>";
echo '<th>Privilege</th>';
echo '<th></th>';
echo '</tr>';
$getUsers = mysqli_query($connection, "SELECT * FROM users");
while($users=mysqli_fetch_assoc($getUsers)){
echo '<form method="post" action="">';
echo '<tr>';
echo '<td>'.$users['username'].'</td>';
echo '<td>'.$users['first_name'].'</td>';
echo '<td>'.$users['last_name'].'</td>';
echo '<td>'.$users['email'].'</td>';
echo '<td>'.$users['year_group'].'</td>';
echo '<td>'.$users['subject'].'</td>';
echo '<td>'.$users['subject2'].'</td>';
echo '<td>'.$users['teacher'].'</td>';
echo '<td>'.$users['teacher2'].'</td>';
echo '<td>'.$users['is_admin'].'</td>';
echo '<td><button name="editUser">Edit</button></td>';
echo '</tr>';
echo '</form>';
}
if (isset($_POST['editUser'])){
$username = $_SESSION['name'];
// ....
}
}
echo '</table>';
?>

最佳答案

<强>1。方法(隐藏输入)

您可以将隐藏输入放入每个 <form></form>可以提交。

<input type="hidden" name="userid" value=...>

<强>2。方法 ( $_SESSION )

第二种方法是保存 ID在 session 中。

优点:

  • 不是那么容易操纵的
  • 您不需要将其粘贴到每个可以提交的表单中。


为了将用户重定向到下一页,发送有关要编辑的行的某种信息会很有帮助。如果您发送的信息每次都不同,您可以使用隐藏输入。可以在 session 中保存每行相同的 ID。

关于php - 为每个用户在按钮点击时传递 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42674169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com