I am new to PHP and am trying to query and delete records from a MySQL db using PHP and an HTML Form. What I want to do is query the db, and then have a "delete button" or checkbox next to each result. When I hit "delete" or select the checkboxes and maybe hit a single delete button, the record(s) would be removed from the db, and I would go to a new HTML page.
I have some code written (see below), but it isn't really working. The search works, and there is a "delete" tag next to each record. However, when I click "delete", I get an error, although the record is sucessfully deleted. Am I trying to do too much in one script?
Any suggestions would be helpful, or if you could point me to a script out there that already does what I want that I could look at, that would be helpful too.
Thanks!
Here is the code:
<?
$hostname = "localhost";
$username = "username";
$password = "pw";
$usertable = "tb";
$dbName = "db";
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
PRINT "Your Search Results: <br><br>";
$query = mysql_query("SELECT * FROM $usertable WHERE $feedback LIKE '%$search%' LIMIT 0, 30 ");
$sql = mysql_query("DELETE FROM $usertable WHERE id=$id"); while
($row = mysql_fetch_array($query))
{
PRINT "<b>First Name: </b> ";
print $row["FirstName"] ;
print (" ");
print ("<br>");
PRINT "<b>Last Name:</b> ";
print $row["LastName"];
print ("<br>");
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $row["id"]);
print ("<p>");
}
?>