#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    137
    Rep Power
    16

    trouble deleting data from database


    Hi, I have a php script that displays data from my database on a page. I want to use [edit] [delete] links to edit/delete that particular row from the database but my script isn't working!

    the delete link is as follows:

    <a href=delete.php?id=$id >delete</a>

    and delete.php is:
    PHP Code:
    <?php

        
    //connect to the DB 
        
    include('../dbs.php');
        
        
    //set up query 
        
    $query "DELETE FROM example where id = '$id'";
        
    //run query 
        
    $result mysql_query($query$connection) or die(mysql_error());
        
        echo 
    "Deletion successful. <a href=list.php>Go back to the main menu</a>";        
    ?>
    the correct id is being displayed in the address bar but the data is not being deleted from the database...

    any suggestions?

    thankyou in advance...
  2. #2
  3. Retired
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Finland
    Posts
    9,115
    Rep Power
    2497
    PHP Code:
    $query "DELETE FROM example where id = '".$_GETT['id']."'"
    Should do some validation stuff as well though, but I am sure it is due to the registered globals stuff -> try searching the stickies / other threads / php manual for mor info.

    HTH

    Cheers,
    Jamie

    >_ My Music Blog | Losing weight @notsoheavyblog | My Tweets

    __________________

    Let the might of your compassion arise to bring a quick end
    to the flowing stream of the blood and tears .....
    Please hear my anguished words of truth.

    __________________
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    137
    Rep Power
    16
    thanks, I have just searched for other threads and I have added the following to my delete.php script (before I run the query):
    PHP Code:
    if ($_GET['id'] <> "") {
        
    $id $_GET['id']; 
    It is now working fine!

    Is there any way of checking with the user that they are sure they want to delete?

    Thanks again...
  6. #4
  7. Shes dancing (obviously)
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2002
    Location
    the far side
    Posts
    527
    Rep Power
    18

    Re: trouble deleting data from database


    Originally posted by skootz
    PHP Code:
        $query "DELETE FROM example where id = '$id'"

    thankyou in advance...
    if u echoed $query the following would have come out
    DELETE FROM example where id = $id;
    since $id is not in the table the query would have failed!

    do a mysql_query () or die (mysql_error()); to see if u are getting successful executions of php-mysql calls.

    look at this for help about using ' ' quotes vs using " "
    HERE
    if not clear pm me

    so basically
    $query = "DELETE FROM example where id = '".$_GET['id']."'";
    can become
    $query = "DELETE FROM example where id = $_GET['id']";
    Last edited by StealthElephant; January 13th, 2004 at 06:27 AM.

    microsofts butterfly is their way off telling u their systems have a **** load of buggs
    Advocating Linux Guide
    Lesbian Linux
    Great & Practical Computer Books

    like the links?

IMN logo majestic logo threadwatch logo seochat tools logo