PHP,仅在提交时来自WHILE循环的一行(id)中的POST数据

问题描述 投票:-1回答:2

问题,如何从id循环中,当username时,仅张贴一行的所需数据(whilesubmit等)?

代码(我将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条件,哪种方法更好?)。 ...

php post submit
2个回答
0
投票
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>
');
}

0
投票

[最后,最好的方法是将input更改为button,其中不显示value,因此value可以是$row['id'],名称在标签<button>NAME</button>之间。

© www.soinside.com 2019 - 2024. All rights reserved.