I am trying to figure out how to delete selected rows from a MySQL database table.
The web site that I am working on has a page that will extract rows, using the "SELECT * FROM .. etc." statement from a database and output them in a table - like the one below (bottom part). I've got that part figured out.
What I am trying to figure out is if the user puts a checkmark in one of the checkboxes (below) how would I write the PHP code to delete one or two of the rows from the MySQL table?
I would appreciate if anyone could provide assistance and show me what to do.
if ($_POST[Submit]){
require_once "./conf/config.inc.php";
//----- Code for MySQL database below here - need help with this part.
$TableName = "Customers";
$Query = "DELETE * FROM $TableName";
$Result = mysql_db_query ($db_info[dbname], $Query, $db_connection);
//--------------------------------
}else{
//------ Form and HTML below here - also need help with this part.
//------ The table below is the output from MySQL "SELECT * FROM $Tablename" code.
echo "<form action=\"$PHP_SELF\" method=\"post\">";
echo "<table>";
echo "<tr>"; //Row one of the table here.
echo "<td><input type=\"checkbox\" name=\"checkbox1\" value=\"delete\"></td>";
echo "<td><input type=\"hidden\" name= \"FirstName\" value=\"John\">John</td>";
echo "<td><input type=\"hidden\" name= \"LastName\" value=\"Doe\">Doe</td><td> </td>";
echo "</tr>";
echo "<tr>"; //Row two of the table here.
echo "<td><input type=\"checkbox\" name=\"checkbox2\" value=\"delete\"></td>";
echo "<td><input type=\"hidden\" name= \"FirstName\" value=\"Fred\">Fred</td>";
echo "<td><input type=\"hidden\" name= \"LastName\" value=\"Black\">Black</td>";
echo "</tr>";
echo "<tr>"; //Row three of the table here.
echo "<td><input type=\"checkbox\" name=\"checkbox2\" value=\"delete\"></td>";
echo "<td><input type=\"hidden\" name= \"FirstName\" value=\"Fred\">Fred</td>";
echo "<td><input type=\"hidden\" name= \"LastName\" value=\"Black\">Black</td>";
echo "</tr>";
echo "</table>";
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit To Delete\">";
echo "</form>";
}
Thanking you in advance.
Volitics