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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.