gpt4 book ai didi

php - 仅更新检查的行 php mysql

转载 作者:行者123 更新时间:2023-11-29 07:31:41 25 4
gpt4 key购买 nike

我试图仅更新表中已检查的行,但没有任何反应这是我的代码

<?php
//database connect select
$result=mysql_query("Select * from ticket_reservation WHERE
validate_status='No'") or die(mysql_error());
while($row=mysql_fetch_array($result))
{
echo "<tr><td><input type='checkbox' id='name' name='name[]'value=".$row['id']."</td><td>".$row['userid']."</td> <td>".$row['busid']."</td><td>".$row['numberofseats']."</td></tr>";
echo "<br>";
}
echo"<tr><td><input type='submit' name='submit' Value='Validate Tickets'> </td></tr>";
if(isset($_POST['submit']))
{
if(is_array($_POST['name']))
{
$qry = "UPDATE ticket_reservation SET validate_status='Yes' WHERE id IN (".implode(',', $_POST['name']).")";
// echo $qry; // For checking the generated sql statement; can be removed
mysql_query($qry);
}
}

?>
</table>
</form>

最佳答案

$checkbox=$_POST['name'];
for($i=0;$i<count($checkbox);$i++)
{
$id = $checkbox[$i];

$sql1 = "UPDATE ticket_reservation set validate_status='Yes' where id = '".$id."' ";
mysql_query($sql1);
}

关于php - 仅更新检查的行 php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32437351/

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