循环直到值为null

时间:2014-09-05 16:00:12

标签: php loops

如果数据库中有用户输入的id,我需要循环删除过程。有人可以帮我这个吗?

 //my php code 
 $ppnum=$_POST['pnum'];

while ($ppnum !== null)) {
$con=mysqli_connect("","","","");
                if (mysqli_connect_errno()){
                  echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }

 mysqli_query($con,"DELETE FROM tbldd WHERE pnum ='$ppnum'");

mysqli_close($con);} 

1 个答案:

答案 0 :(得分:0)

也许你想要这个?假设$ _POST ['pnum']是逗号分隔的ID列表。

$ppnum=$_POST['pnum'];

$con=mysqli_connect("","","","");
if (mysqli_connect_errno()){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"DELETE FROM tbldd WHERE pnum in ($ppnum)");

mysqli_close($con);

但你必须检查$ _POST ['pnum']对抗sql注入攻击。