Jump to content

Recommended Posts

Hello,

 

with the code below i delete 1 row even if several rows are selected, what should i do to be able to delete as much rows as much i select at once.

 

<?php
mysql_connect("localhost", "root", "") or die ("Could not connect");
mysql_select_db("db1") or die ("Could not connect to DB");
if ($_POST['delete'])

{

$deleteID = $_POST['delete'];

mysql_query("DELETE FROM dbtable WHERE id='$deleteID'") or die(mysql_error());

echo "The Row Number $deleteID has been Successfully Removed";

  
    }
else 

{ 

echo "please select at least one row, to delete it";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/72597-delete-multiple-rows-phpmysql/
Share on other sites

Firstly, you would need to make your form use arrays, then you simply implode on that array to form your query. eg;

 

<form method="post">
  <input type="checkbox" name="del[]" value="1">
  <input type="checkbox" name="del[]" value="2">
  <input type="checkbox" name="del[]" value="3">
  <input type="submit" name="submit">
</form>
<?php

  if (isset($_POST['submit'])) {
    $sql = "DELETE FROM dbtable WHERE id IN('" . implode("','",$_POST['del']) . "');";
    if (mysql_query($sql)) {
      echo "The Rows Number " . implode(" ",$_POST['del']) . " where Successfully Removed";
    } else { 
      echo "please select at least one row, to delete it";
    }
  }

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.