RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 822 | Replies: 1
Reply
Join Date: Mar 2007
Posts: 13
Reputation: elderp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
elderp elderp is offline Offline
Newbie Poster

Simple Delete problem

  #1  
Mar 15th, 2007
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.
<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.
Last edited by elderp : Mar 15th, 2007 at 6:42 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2005
Posts: 716
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 6
Solved Threads: 44
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Master Poster

Re: Simple Delete problem

  #2  
Mar 16th, 2007
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]
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!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:26 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC