Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers

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.

share|improve this answer
 
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 –  jscionti Sep 30 at 3:46

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

$sql="DELETE FROM bookings WHERE BookingNo=".num; //here should be $num
share|improve this answer
1  
Wow I can't believe I missed that; thanks. Fixed but still not working sorry. –  jscionti Sep 30 at 3:44
 
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. –  Console Sep 30 at 3:52
 
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 –  jscionti Sep 30 at 4:05
 
What i meant was to wrap your table name with backticks (`). –  Console Sep 30 at 5:05
 
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 –  jscionti Sep 30 at 6:40
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.