1
if(isset($_POST['Active']) && isset($_POST['Box'])){ 

    $status= $_POST['activation'];

    foreach($_POST['Box'] as $remove_ch){


        $sqlupd= "update Pre_Enrollment set Status='$status' where Checkbox_Id='$remove_ch'";
        $resultupdate = mysqli_query($database,$sqlupd) or die (mysqli_error($database));

        if($resultupdate){
            echo "<meta http-equiv=refresh content=\"0; URL=../Admin/admin pre-enrollment.php\">";
        }

    }

}  

from this code, i need to update the status using checkbox but its update only the last row I have, and then it allows me to update the rest with the same choice of first one, considering that status are option list. can you please tell me what is wrong?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
R.A
  • 23
  • 1
  • 6
  • Use a `header` in place of the `meta`. You set the status outside of the loop. Is there only one status field? You could just use an `in` and update all the records at once. You are open to SQL injections, parameterize the query. Also do you have `Active` and `activation` inputs? – chris85 May 21 '17 at 17:53
  • I have active and inactive options. and "Active" is the button, "Activation" is the name of the option. – R.A May 21 '17 at 17:58
  • Your code is vulnerable to SQL injection, you need to fix this. – Enstage May 21 '17 at 23:27
  • how can I fix it? – R.A May 22 '17 at 07:52

1 Answers1

0

Firstly, please be careful, you might be exposed to SQL injection. Concatenating strings is not the best option, try running parametrized queries.

Secondly, how does the tag look like? A common mistake is to forget "[]" after the field. An example:

<input type="checkbox" name="Box[]" value="{ID}">

Thirdly, echo "<meta..>" should probably be outside of the foreach loop.

user3429660
  • 2,420
  • 4
  • 25
  • 41