I have a problem when i try to delete a record from my database with php . I try to do this with checkboxes, but the record remains and I don't get any errors.
Here's the file where the records are displayed
<?php
$db = mysql_connect("localhost","username","password")
or die("Could not connect : ". mysql_error());
mysql_select_db("databasename", $db);
$query = "select * from test order by Id";
$result = mysql_query ($query,$db)
or die ("Query failed : ". mysql_error());
//Printing Results in Html
print "<html><head><title>database test</title></head><body bgcolor=\"lightblue\">\n";
print "<span style=\"position:absolute; top:200px;left:200;\">\n";
print "<form action=\"delete.php\" method=\"post\">\n";
print "<table border=\"1\" bordercolor=\"black\" bgcolor=\"white\">\n";
print "<tr bgcolor=\"lightblue\"><td>Voornaam</td><td>Achternaam</td></tr>\n";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("<tr><td>$row[1]</td><td>$row[2]</td><td bgcolor=\"lightblue\">
<input type=\"checkbox\" name=\"$row[Id]\" value=\"1\"/></td></tr>");
}
print "</table>\n";
print "<input type=\"submit\" value=\"delete\">\n";
print "</form>\n";
print "</span>\n";
require ('form.html');
print "</body></html>";
mysql_free_result($result); // free resultset
mysql_close($db); //close //close connection
?>
And this is the code which i use to delete the records:
<?php
//maakt variabelen uit formulier toegankelijk
$Id = $_POST['name'];
print "$Id \n";
//database verbinding
$db = mysql_connect("localhost","username","password")
or die("Could not connect : ". mysql_error());
// query uitvoeren
mysql_select_db("databasename", $db);
$query = "delete from test where Id = '$Id'";
$result = mysql_query ($query,$db)
or die ("Query failed : ". mysql_error());
echo "Thank you, records were succesfully deleted!<br />";
// redirect naar een andere pagina
print "Click <a href=\"http://link">here</a> to go back to the page";
mysql_free_result($result); // free resultset
mysql_close($db); //close //close connection
?>