I have a table in mysql and I’m printing it on screen by this code:
include ('mysql_con.php');
mysql_select_db("jaz", $con);
$res1 = mysql_query("SELECT * FROM hovno ORDER BY id DESC");
echo "<form action='delete_from_db.php' method='POST'>";
echo "<table border='1'>";
echo "<tr>";
echo "<td colspan='6'>" . "<input type='submit' value='Delete Article'>" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . "<b>" . "Delete" . "</b>" . "</td>";
echo "<td>" . "<b>" . "ID" . "</b>" . "</td>";
echo "<td>" . "<b>" . "Date" . "</b>" . "</td>";
echo "<td>" . "<b>" . "Title" . "</b>" . "</td>";
echo "<td>" . "<b>" . "Preview" . "</b>" . "</td>";
echo "<td>" . "<b>" . "Author" . "</b>" . "</td>";
echo "</tr>";
while($a=mysql_fetch_array($res1)) {
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='checkbox[]' value='" . $a["id"] . "'>" . "</td>";
echo "<td>" . $a["id"] . "</td>";
echo "<td>" . $a["created"] . "</td>";
echo "<td>" . $a["title"] . "</td>";
echo "<td>" . $a["preview"] . "</td>";
echo "<td>" . $a["author"] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
So I’m putting id’s as checkbox values into array.
In another php file I wan’t to use this id’s in array to delete this records with those id’s. I don’t know what code to use for that buy i tried this:
<?php
include ('mysql_con.php');
mysql_select_db("jaz", $con) or die(mysql_error());
$del[]=$_POST["checkbox"];
$res1 = mysql_query("SELECT * FROM hovno WHERE id='$del'") or die(mysql_error());
while($a = mysql_fetch_array($res1)){
$b = $a["id"];
mysql_query("DELETE FROM hovno WHERE id ='$b'") or die(mysql_error());
}
?>
Any idea how to actually make it work? Thanks
1 Answer