gpt4 book ai didi

php - 根据选定的 itemid 更新 foreach 循环中的 Mysql 行

转载 作者:行者123 更新时间:2023-11-29 21:58:08 24 4
gpt4 key购买 nike

我试图根据选定的复选框更新 mysql 中的一些行,但我的查询正在更新表中的所有行。请检查以下代码:

    if (!empty($_POST['checkbox'])) 
{
// Loop to store and display values of individual checked checkbox.
foreach ($_POST['checkbox'] as $selected) {
$sql1="UPDATE Items SET Status='1' WHERE Item_Id='$selected'";
$result1=mysql_query($sql1);
if (!$result1)
{
echo "Error While updating";
}
else
{
header("Refresh: 2;url=Main_Menu.php");
mysql_close($conn);
echo "<p>Todays Menu Updated <a href='Main_Menu.php>Click here</a> if you are not redirected automatically in 2 seconds<br /></p>";
}
}

最佳答案

这里 if (!empty($_POST['checkbox'])) 您应该使用复选框的名称。

例如,如果您的 html 如下所示:

  <input type="checkbox" name="checkbox_name" />

您应该编写如下 if 语句:

if (!empty($_POST['checkbox_name']))

这同样适用于 foreach 语句以及在 sql 语句中使用它。

关于php - 根据选定的 itemid 更新 foreach 循环中的 Mysql 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32919391/

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