单击复选框中的更新数据

时间:2014-04-16 14:33:59

标签: php database

我的代码到目前为止。数据被正确拉出

    if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM Request");

echo "<table border='1'>

<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Prayer Request</th>
<th>Deactivate Request</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Reg_F_Name'] . "</td>";
  echo "<td>" . $row['Reg_L_Name'] . "</td>";
  echo "<td>" . $row['Reg_Request'] . "</td>";
  echo "<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"".$rows['Reg_ID']. "\" /></td>";  
  echo "</tr>";
  }
echo "</table>";

echo 
"<form action='' method='post'> 
<input type='submit' name='use_button' value='Update' /> 
</form>"; 

if(isset($_POST['use_button'])) 
{ 
    echo "hey"; 
$del_id = $_POST['checkbox']; 
$detectinglocations = 'your database table name';

foreach($del_id as $value){
   $sql = "Update Request  set Reg_Status=0 WHERE Reg_ID='".$value."'";
   $result = mysql_query($sql);
}




}

mysqli_close($con);

?>

单击“提交”时没有任何反应。我希望它为每个单击的复选框更新reg_Status为0。那么我的问题是什么。提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试在每个复选框之前添加一个与复选框名称相同的输入隐藏字段,值为0。

未选中时,复选框不会发布。