问题,如何从id
循环中,当username
时,仅张贴一行的所需数据(while
,submit
等)?
代码(我将POST
用作“函数” delete_member
,条件为if
,哪种方法更好?)]]
if(isset($_POST["delete_member"])) { # Delete member echo $id=$_POST["id"]; $sql="delete from members where id = $id"; mysqli_query($db,$sql) ? $status = true : $status = false; message($status); } $select_members = mysqli_query($db,"select * from members"); while($row = mysqli_fetch_array($select_members)) { echo(' <tr> <td><input type="text name="id" value="'.$row['id'].'" readonly></td> <td><input type="text name="username" value="'.$row['username'].'" readonly></td> <td><input type="text name="password" value="'.$row['password'].'" readonly></td> <td><input type="text name="active" value="'.$row['active'].'" readonly></td> <td><input type="submit" name="delete_member" value="Smazat"></td> <td><input type="submit" name="send_email" value="Odeslat email"></td> <tr> '); }
没有存储在
echo $id=$_POST["id"];
中。可以从id
发送input type="submit"
吗?例如这样。
<input type="submit" name="delete_member" id=".$row['id']." value="Smazat">
谢谢。
问题,在提交时,如何从while循环中仅发布一行所需的数据(ID,用户名等)?代码(我将POST用作“函数” delete_member,并使用if条件,哪种方法更好?)。 ...
if(isset($_POST["delete_member"]))
{
# Delete member
echo $id=$_POST["id"];
$sql="delete from members where id = $id";
mysqli_query($db,$sql) ? $status = true : $status = false;
message($status);
}
$select_members = mysqli_query($db,"select * from members");
while($row = mysqli_fetch_array($select_members))
{
echo('
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['username'].'</td>
<td>'.$row['password'].'</td>
<td>'.$row['active'].'</td>
<td><form method="post" action="HERE_FILL_IN_SCRIPT_URL"><input type="hidden" name="id" value="'.$row['id'].'"><input type="submit" name="delete_member" value="Smazat"><input type="submit" name="send_email" value="Odeslat email"></form></td>
<tr>
');
}
[最后,最好的方法是将input
更改为button
,其中不显示value
,因此value
可以是$row['id']
,名称在标签<button>NAME</button>
之间。