Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 822 | Replies: 1
![]() |
•
•
Join Date: Mar 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
I want to be able to enter an employee # 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.
Then I have the form action that doesn't seem to be working right it says it deletes but it really doesn't.
Not sure what is up it is telling me it worked but I go into the db and the information is still there.
<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>
<? @$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.
Last edited by elderp : Mar 15th, 2007 at 6:42 pm.
Try putting in some error checking when you have made an SQL query.
eg:
[php]
$query = 'DELETE FROM info647_emp WHERE empno = $id ON DELETE CASCADE';
// i've changed from here on to check for errors
$result = mysql_query($query);
if ($result) {
// ok
echo "Row deleted!";
} else {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
[/php]
eg:
[php]
$query = 'DELETE FROM info647_emp WHERE empno = $id ON DELETE CASCADE';
// i've changed from here on to check for errors
$result = mysql_query($query);
if ($result) {
// ok
echo "Row deleted!";
} else {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
[/php]
Last edited by digital-ether : Mar 16th, 2007 at 10:50 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode