Below code !Gives me check boxes and a delete button, In input tag all check box have same name (check)!! There check box can be retreive from database with id .
Problem Is:: when I am selecting multiple checkbox for deletion…only last one checkbox is deleted ! means it can delete 1 data from a database.
url like -> http://localhost/demo/delete.php?check=10&check=13&check=14&submit=Delete
I need while I am selecting a checkbox more than 1 checkbox ,check box datas is deleted from database ! Any one help me to overcome this problem thanks
-
index.php
<?php $sql = mysql_connect('localhost', 'root', ''); mysql_select_db('database_section', $sql); ?> <form name="checkbox" method="get" action="delete.php"> <table> <tr> <?php $sql = "select * from data"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { ?> <td><input type="checkbox" name="check" value="<?php echo $row['id']?>"><?php echo $row['data'];?> </td> <?php } ?> <tr> <td><input type="submit" name="submit" value="Delete"></td> </tr> </table> </form> -
Now, In delete.php..code below…
<?php $sql = mysql_connect('localhost', 'root', ''); mysql_select_db('database_section', $sql); if ($_REQUEST['submit']) { $abc = $_GET['check']; $sql = "Delete from data where id=$abc"; $result = mysql_query($sql) or die(mysql_error()); if (isset($result)) { echo "data deleted"; } else { echo "not possible"; } } ?>
Use check box as an array holder. name it as check[] to hold all selected values. And on post you will get the selected array list.
Now your $abc will be a array, use foreach in delete.php to get the checked ids.