php - Update Mysql rows in foreach loop based on selected itemid -
i trying update rows in mysql based on selected checkbox,but query updating rows in table. please check below code:
if (!empty($_post['checkbox'])) { // loop store , display values of individual checked checkbox. foreach ($_post['checkbox'] $selected) { $sql1="update items set status='1' 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 not redirected automatically in 2 seconds<br /></p>"; } }
here if (!empty($_post['checkbox']))
should use name of checkbox.
for instance, if html below:
<input type="checkbox" name="checkbox_name" />
you should write if statement below:
if (!empty($_post['checkbox_name']))
the same holds foreach
statement , use of in sql statement.
Comments
Post a Comment