'Delete From' Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Philth
    New Member
    • Oct 2007
    • 38

    'Delete From' Issue

    Hi there,

    Can anyone spot why this scrip isn't working.

    It returns "row deleted" fine, yet doesn't delete.

    Code:
    <?
    include("connect.php"); 
    
    if($_GET["cmd"]=="delete")
    {
        mysql_query("DELETE FROM events WHERE eventNumber='$id'");
    
        $result = mysql_query or die("Error: ". mysql_error());
        echo "Row deleted!";
    }
    ?>
    
    
       
       
       
        <?
    include("connect.php"); 
    
    if(!isset($cmd)) 
    {
       $result = mysql_query("select * from events order by eventName"); 
       
       while($r=mysql_fetch_array($result)) 
       { 
    
          $title=$r["eventName"];
          $id=$r["eventNumber"];
    	    $location=$r["eventLocation"];
    		  $date=$r["eventDate"];
         
    	 echo "<span class='smalltitle'>$title</span><br><span class='bodytext'>$location<br>$date</span><br> "; 
          echo "<a href='delete_event.php?cmd=delete&id=$id' class='links'>$title - Delete</a><br><br>";
    	  
        }
    }
    ?>
    Many thanks.
  • gopan
    New Member
    • Apr 2009
    • 41

    #2
    try to echo the value of $id too... it is blank thats why its not removing the row

    change $id to $_GET['id']... and check

    Comment

    • Philth
      New Member
      • Oct 2007
      • 38

      #3
      Sorry, I don't understand. The $id in the DELETE FROM query?

      Comment

      • gopan
        New Member
        • Apr 2009
        • 41

        #4
        yup... in query... change it to $_GET['id']

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          line #6: nothing will happen if the query fails.

          line #8: an undefined constant is redefined as variable (not enough to trigger die()), if you have error notices on you’ll receive a notice about that

          Comment

          • Philth
            New Member
            • Oct 2007
            • 38

            #6
            Great, thanks alot guys.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              sure, I’m glad I could help.

              Comment

              Working...