Results 1 to 13 of 13

Thread: Cannot delete a row with PHP & MySQL

Hybrid View

  1. #1
    Member n0vembr's Avatar
    Join Date
    Jun 2005
    Location
    pilipinas kong minumutya
    Posts
    60

    Re: Cannot delete a row with PHP & MySQL

    dont u think it should be :

    Code:
    $result = mysql_query("DELETE FROM" . $data[0] ."  WHERE ID IN(" .$data[1] . ")");
    Having it like this
    Code:
    $result = mysql_query("DELETE FROM $data[0] WHERE ID IN($data[1])");
    would make the SQL query exactly "DELETE FROM $data[0] WHERE ID IN($data[1])", which obviously would give an error...i think
    thanks..salamat..arigatou..gracias

  2. #2

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Cannot delete a row with PHP & MySQL

    You can have arrays in sql queries like I have just fine. I do it in other queries to update my tables.

    Quote Originally Posted by n0vembr
    dont u think it should be :

    Code:
    $result = mysql_query("DELETE FROM" . $data[0] ."  WHERE ID IN(" .$data[1] . ")");
    Having it like this
    Code:
    $result = mysql_query("DELETE FROM $data[0] WHERE ID IN($data[1])");
    would make the SQL query exactly "DELETE FROM $data[0] WHERE ID IN($data[1])", which obviously would give an error...i think
    Tried it with the exact same results

    I have no clue what's going on

  3. #3
    Member n0vembr's Avatar
    Join Date
    Jun 2005
    Location
    pilipinas kong minumutya
    Posts
    60

    Re: Cannot delete a row with PHP & MySQL



    did u try manually executing the statement in a query analyzer tool?
    thanks..salamat..arigatou..gracias

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Cannot delete a row with PHP & MySQL

    Quote Originally Posted by n0vembr


    did u try manually executing the statement in a query analyzer tool?
    Use echo() to output the query text an ensure it is what you expect. Then try n0vemberssuggestion of executing that exact text on the command line.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    New Member
    Join Date
    Aug 2005
    Posts
    1

    Re: Cannot delete a row with PHP & MySQL

    I think you're forgetting there have to be quotes round the string in the query.
    So I think it's like this:

    Code:
    $result = mysql_query("DELETE FROM '" . $data[0] ."'  WHERE ID IN '" .$data[1] . "'");
    I added the single quotes... (if ID is a number in your database, you can delete the single quotes there)

    I hope it works, it's my first post here on the forum, and i just know the basics of PHP/MySQL, so don't shoot me if I'm wrong.

  6. #6

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Cannot delete a row with PHP & MySQL

    Quote Originally Posted by n0vembr


    did u try manually executing the statement in a query analyzer tool?
    Ran the same statement in PHP Admin and it worked fine.
    Quote Originally Posted by visualAd
    You need to use urly brackets to enclose arrays:
    { }
    Code:
    $result = mysql_query("DELETE FROM {$data[0]} WHERE ID IN({$data[1]})");
    What? I have several statements which alter rows and insert rows with arrays and they work fine without brackets. Why would delete require them? I'll try it just to double check but I don't understand that.
    Quote Originally Posted by visualAd
    Use echo() to output the query text an ensure it is what you expect. Then try n0vemberssuggestion of executing that exact text on the command line.
    Havn't had the chance of using echo or print. I'm going to give this a try later but it seems the issue is specifically with the sql query
    Quote Originally Posted by Geert
    I think you're forgetting there have to be quotes round the string in the query.
    Shouldn't matter and I've tried that anyway.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Cannot delete a row with PHP & MySQL

    Quote Originally Posted by n0vembr
    dont u think it should be :

    Code:
    $result = mysql_query("DELETE FROM" . $data[0] ."  WHERE ID IN(" .$data[1] . ")");
    Having it like this
    Code:
    $result = mysql_query("DELETE FROM $data[0] WHERE ID IN($data[1])");
    would make the SQL query exactly "DELETE FROM $data[0] WHERE ID IN($data[1])", which obviously would give an error...i think
    You need to use urly brackets to enclose arrays:
    { }
    Code:
    $result = mysql_query("DELETE FROM {$data[0]} WHERE ID IN({$data[1]})");
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width