2

I have read through this and this post, which looks to be the most similar, but it has not solved my problem.

I have the below while loop working to display results from my database. The specific line of question in the while loop is this (note: it is within a form):

while($row = mysqli_fetch_array($result)){
<input type='checkbox' name='check_box_delete[]' value='".$row['BookingNo']."'>
}

The rest of the form data passes through fine except for the checkboxes. In the following php page, I have this:

if(isset($_POST['check_box_delete'])){
    foreach($_POST['check_box_delete'] as $id){
        $sql="DELETE FROM bookings WHERE BookingNo='".$id."'";
        if (!mysqli_query($con,$sql)){
            die('Error: ' . mysqli_error($con));
        }
    echo $id." deleted.";
}

The page echos deleted but no associated $id. I suspect my processor.php is not getting the booking number at all.

2 Answers 2

0

When it says "Record successfully deleted" it only means that there are some checkboxes have been checked.

Use mysqli_affected_rows() function to determine if you deleted something. It will show you the situation.

Sign up to request clarification or add additional context in comments.

1 Comment

The "Record successfully deleted" means that the code is going to the right spot (I've edited OP for clarification) sorry. I've added echo mysqli_affected_rows() under the echo "Record..." but nothing is printing
0

Change num to $num in your delete query and try again.

$sql="DELETE FROM bookings WHERE BookingNo=".num; //here should be $num

8 Comments

Wow I can't believe I missed that; thanks. Fixed but still not working sorry.
Try changing your query to this "DELETE FROM bookings WHERE BookingNo='$num'"; (Put backtick in table name) And Record successfully deleted will be always displayed because you are just echoing it without checking if the record is actually deleted or not.
Do you mean this: else{ $sql="DELETE FROM bookings WHERE BookingNo='$num'"; $result=mysqli_query($sql); } That's what I now have but still nothing
What i meant was to wrap your table name with backticks (`).
Right, nope, still nothing sorry. The query is working fine, I'm sure, the problem lies with getting the correct $booking id from the form
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.