By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

Deleting Rows - Should be an easy one!

P: 38
Hello folks,

Hopefully this will be an easy one for most of you guys. I don't delve into PHP much so I'd appreciate some help.

The aim of the script below is to display a collection of rows with the aim of specifying one for eventual deletion.

It returns the "row deleted" echo fine, but doesn't actually delete anything.

Expand|Select|Wrap|Line Numbers
  1.     <?
  2. include("connect.php"); 
  3.  
  4. if(!isset($cmd)) 
  5. {
  6.    $result = mysql_query("select * from events order by eventName"); 
  7.  
  8.    while($r=mysql_fetch_array($result)) 
  9.    { 
  10.  
  11.       $title=$r["eventName"];
  12.       $id=$r["eventNumber"];
  13.         $location=$r["eventLocation"];
  14.           $date=$r["eventDate"];
  15.  
  16.      echo "<span class='smalltitle'>$title</span><br><span class='bodytext'>$location<br>$date</span><br> "; 
  17.       echo "<a href='delete_event.php?cmd=delete&id=$id'>$title - Delete</a><br><br>";
  18.  
  19.     }
  20. }
  21. ?>
  22.  
Expand|Select|Wrap|Line Numbers
  1. <?
  2. if($_GET["cmd"]=="delete")
  3. {
  4.     $sql = "DELETE FROM events WHERE eventNumber=$id";
  5.     $result = mysql_query($sql);
  6.     echo "Row deleted!";
  7. }
  8. ?>
  9.  
Many thanks.
Aug 5 '09 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
If there's an error generated by mysql, it won't tell you - you have to find out for yourself.

Update your code to this:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if($_GET["cmd"]=="delete")
  3. {
  4.     $sql = "DELETE FROM events WHERE eventNumber=$id";
  5.     // Notice mysql_error()
  6.     $result = mysql_query($sql) or die("Error: ". mysql_error());
  7.     echo "Row deleted!";
  8. }
  9. ?>
Aug 5 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.