Jump to content


Photo

Delete Function


  • Please log in to reply
2 replies to this topic

#1 jukie

jukie

    Member

  • Members
  • PipPip
  • 24 posts

Posted 18 June 2013 - 10:39 AM

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"); 

?>



#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,649 posts
  • LocationBonita, FL

Posted 18 June 2013 - 11:58 AM

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.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 jukie

jukie

    Member

  • Members
  • PipPip
  • 24 posts

Posted 20 June 2013 - 07:44 AM

Tried it with no quoted and still no success. :sweat:






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com