Jump to content

Delete Function


jukie

Recommended Posts

Hello

I'm trying to allow the user to delete a record from a web app. I copied a tutorial on deleting data but struggling to work it out. My php code is

<?php
      include "connection.php";//database connection
       $order = "SELECT * FROM "members" WHERE Username= '".mysql_real_escape_string($_SESSION['Username'])."' ORDER BY DATE DESC ";;
      $result = mysql_query($order);
      
      while ($row=mysql_fetch_array($result)){
       
           echo ("<tr><td>$row[Name]</td>");
           echo ("<td>$row[SecondName]</td>");
           echo ("<td><a href=\"deletebookmark.php?id=$row[ID]]\">Delete</a></td></tr>");


        
      }
      ?>

The ID in the final row is the id of the record (members) (this could be the issue)

 deletebookmark.php code

<?php



include "connection.php"; 

 
$order = "DELETE FROM "members" 

        WHERE "" ='$ID'"; 

mysql_query($order); 

header("location:member.php"); 

?>

Link to comment
https://forums.phpfreaks.com/topic/279318-delete-function/
Share on other sites

You need to specify the column name to test against in the WHERE clause. The table name and column name should NOT be quoted.

 

DELETE FROM members WHERE ID=$ID
You need to define what $ID is. Based on the code, you want $_GET['id']. You will need to sanitize it to prevent sql injections, using intval will work assuming the id is a number.
Link to comment
https://forums.phpfreaks.com/topic/279318-delete-function/#findComment-1436665
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.