I want to be able to enter an employee number from my system and have it delete. I have a form that prompts the user to enter an employee number. That seems to be working fine.
<html><TD WIDTH="29%" HEIGHT="60"><DIV ALIGN="LEFT"><BR>Input
the Reference, to make sure we have the right one:<BR><BR><FONT SIZE="1">(quick
reference listed below for your convenience)</FONT></DIV>
<form method=POST action="drop1.php">
<DIV ALIGN="LEFT"><INPUT TYPE="text" NAME="record" SIZE="50" MAXLENGTH="50"><BR><BR><WIDTH="51" HEIGHT="46" ALIGN="ABSMIDDLE" BORDER="1"><INPUT TYPE="submit" VALUE="Delete Employee"></DIV></form></TD></TR><TR><TD WIDTH="29%"><DIV ALIGN="LEFT">
<?php
// Show simple format of the records so person can choose the reference name/number
// this is then passed to the next page, for all details
$db = mysql_connect($host,$username,$password);
mysql_select_db($database,$db) or die ('Unable to connect to database');
$q="SELECT * FROM info647_emp ORDER BY empno ASC";
$result = mysql_query($q,$db)
or die(" - Failed More Information:<br><pre>$q</pre><br>Error: " . mysql_error());
$num_rows = mysql_num_rows($result);
if ($myrow = mysql_fetch_array($result)) {
echo "<br>A Quick View<BR><br>";
echo "<table border=1>\n";
echo "<tr><td><b>Empno:</b></td><td>Last:</td><td>First:</td><td>Addr:</td></tr>\n";
do {
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow["empno"], $myrow["emplast"], $myrow["empfirst"], $myrow["emphaddr"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "$ref: That record appears to be unavailable";
}
mysql_free_result($result);
mysql_close($db);
include("footer.html");
?></DIV></TD></html>
Then I have the form action that doesn't seem to be working right it says it deletes but it really doesn't.
<?
@$id =$_POST['record'];
$db = mysql_connect($host,$username,$password);
mysql_select_db($database,$db) or die ('Unable to connect to database');
$query = 'DELETE FROM info647_emp WHERE empno = $id ON DELETE CASCADE';
mysql_query($query);
echo "Row deleted!";
echo " Bye. $id";
include("footer.html");
?>
Not sure what is up it is telling me it worked but I go into the db and the information is still there.