Connecting Tech Pros Worldwide Help | Site Map

Deleting Rows - Should be an easy one!

Member
 
Join Date: Oct 2007
Posts: 36
#1: Aug 5 '09
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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Aug 5 '09

re: Deleting Rows - Should be an easy one!


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. ?>
Reply