3

I have a form that enables user to select several items:

<table>
<form name="delete" action="proceed.php" method="post">
<?php 
 require_once 'cnn.php';
 $viewPhoto = mysqli_query($cnn, "SELECT * FROM competition WHERE round = 2 ORDER BY id Desc");


                while($row = mysqli_fetch_array($viewPhoto)) {    ?>

<tr><td><input type="checkbox" name="check[]" value="<?php echo $row['id']; ?>"></td>
<td><?php echo $row['id']; ?></td>
<td><img title="" src="<?php echo $row['url']; ?>"  width="178" height="150" /></td></tr>                   

<?php } ?>
<input type="submit" name="delete" value="Delete items">
</form>
</table>

The proceed.php then includes:

<?php
 require_once 'cnn.php';
 $sql = mysqli_query($cnn, "SELECT * FROM competition");

 if(isset($_POST['delete'])){
   foreach ($_POST["check"] as $id){
   $sql = "DELETE FROM soutez WHERE id='$id'";
}
   echo "Items deleted";
}
?>

However, the items are not deleted from database. Where could be the mistake?

9
  • Are you getting any error? Also mention where you could stucked? Commented Jun 16, 2014 at 6:25
  • hint: there is no mysqli_query(). you did not execute it. tip: use parameterized queries :) Commented Jun 16, 2014 at 6:25
  • 1
    Maybe this is relevant: You are selecting from "competition" and deleting from "soutez". Commented Jun 16, 2014 at 6:27
  • @JeremyMiller : How do you say that? User doesn't share any DB schema. Is there any rules where we select, on that table record only can able to delete? Commented Jun 16, 2014 at 6:31
  • Jeremy: It was just a mistake in my translation: competition = soutez in Czech :) Commented Jun 16, 2014 at 6:33

1 Answer 1

4

You are missing executing actual query in loop for deleting record

<?php
 require_once 'cnn.php';
 $sql = mysqli_query($cnn, "SELECT * FROM soutez");

 if(isset($_POST['delete'])){
   foreach ($_POST["check"] as $id){
   $sql = "DELETE FROM soutez WHERE id='$id'";
   //Here you are missing below statement
   mysqli_query($cnn, $sql);
}
   echo "Items deleted";
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Sadikhasan. This is perfect!

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.