I am still very new to PHP and MySQL, but I am making a database while using all the information I can get out of this book. I am trying to make an employee database that you can add people, search them by name, and then delete the person you just searched. The last part is where I am having some major problems. I understand how to delete a specific employee by using sql queries, I just don't get how to pass the information from the last searched employee and then delete them. I will include the code for searching the employees and then my delete page, since the others pages I am pretty certain are correct.
PHP code
<?php
echo "<h2>Search Results:</h2><p>";
$find = $_POST['find']
mysql_connect('localhost', 'username', 'password');
mysql_select_db('employedatabase');
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim($find);
$EmployeeName = mysql_query("SELECT * FROM employee_data WHERE upper($EmployeeName) LIKE '%$find%'");
while ($result = mysql_fetch_array($EmployeeName))
{
echo $result['employee_name'];
echo "<br>";
}
$anymatches = mysql_num_rows($EmployeeName);
if ($anymatches == 0)
{
echo "Sorry, but we could not find that employee...<br><br>";
}
echo "<b>Searched For:</b> " . $find;
?>
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Employee Results</title>
</head>
<body>
<h2>Employee Results</h2>
<form name="Delete" method="POST" action="delete.php">
Delete Employee: <input type="text" name="find"/>
<input type="submit" name="Delete" value="Delete"/>
</form>
</body>
</html>
Delete.php code
<?php
mysql_connect('localhost', 'username', 'password');
mysql_select_db('employedatabase');
$find = $_POST['find'];
$strSQL = "DELETE * FROM employee_data WHERE employee_name = $find";
header("Location: Home.html");
?>