vendredi 2 octobre 2015

Update Mysql rows in foreach loop based on selected itemid

I am trying to update some rows in mysql based on selected checkbox,but my query is updating all the rows in the table. Please check below code:

    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>";
   } 
   }




Aucun commentaire:

Enregistrer un commentaire