Hi, I am new to PHP and I try to display some records and chechboxes (with the id from the database as value) from a database. By checking some of the records I would like to make delete them by submiting. My problem is that I don't know how to pass the several id's of the checkboxes to the delete.php file.
Do anyone can help me?
Thanks,
Joanthan
this is the data.php file:
<?php
$db = mysql_connect("localhost","root","root")
or die("Could not connect : ". mysql_error());
mysql_select_db("text", $db);
$query = "select * from usr 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>Id</td><td>Voornaam</td><td>Achternaam</td></tr>\n";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("<tr><td>$row[Id]</td><td>$row[0]</td><td>$row[1]</td><td
bgcolor=\"lightblue\">
<input type=\"checkbox\" name=\"Id\" value=\"$row[Id]\"/></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
?>
I am thinking of doing something with foreach, like displaying the id's of the checkboxes to start, but it doesn't work.
<?php
foreach($_POST as $Id){
print "This is the checkbox's value: $Id";
}
?>