SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you tell me how to delete a row from a mysql database?

    I tried this, but it didn't work.

    Code:
    mysql_query("DELETE FROM pricewatch_backup WHERE id=$id");
    Thanx in advance.

  2. #2
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well what your trying seems to be correct..
    why dun you try this and see the error it pops out?

    $query = mysql_query("DELETE FROM pricewatch_backup WHERE id=$id");

    if (!$query) {
    echo mysql_error();
    }
    Last edited by kunal; Mar 22, 2001 at 04:29.
    i dunno...

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should be:

    Code:
    mysql_query("DELETE FROM pricewatch_backup WHERE id='$id' ");
    //note the single quote around $id
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Things to watch out for.

    In the table, is the id column called:

    ID or id or Id

    And also, try printing out $id

    Code:
    print $id;
    If it prints out a number, then it should work, otherwise, it means that the ID is not being fetch correctly.

    Lastly, you don't need the single quotes most of the time.

    Peter

  5. #5
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's an integer, you don't need single quotes, but if it's a string/chars, without the single quotes, MySQL will complain.
    So, in general, put the single quotes, you don't have to care what value is $id (integer or string or chars)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help. It turns out my browser didn't refresh the page properly...

    Yes, ID is an integer. So, you don't need to put quote between the variable.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    mysql_query("DELETE FROM pricewatch_backup WHERE id = '$id'");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •