Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Syntax error from query??

    Hiya all.
    I am a newbie to MySQL and PHP so appologies if this is a daft error, i just cant see what is wrong?? What i am trying to do is query the database based on 2 conditions and delete the match.

    Here is my query -
    PHP Code:
    $query mysql_query(sprintf("DELETE * FROM Journey WHERE journeyName='$jName' AND loginName='%s'"mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' mysql_error()); 
    But when i run the query i am getting this error message -
    Code:
    SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM Journey WHERE journeyName='supermarket' AND loginName='hannahMc1'' at line 1
    I just cant see what is wrong with it? Can anyone help?
    Thank u so much, Stephen.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    DELETE  FROM Journey ........
    No need to specify the columns as we do in SELECT, since it's not possible.
    See http://dev.mysql.com/doc/refman/5.0/en/delete.html
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Removing the asterix just leaves me with this error message now -

    Code:
    SQL Error: Query was empty
    ??? Im confused why its not working

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Im confused why its not working
    Post rest of your code.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    That means that the criteria you have given points to no record in your database, try checking your WHERE criteria...

  • #6
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
                
    if ($_POST['delete'] == 'Delete this ride')
                {
                    
    $jName=($_POST['deleteRide']);
                    
                    
    error_reporting(E_ALL);
        
                    include (
    'connect.php'); 
                    
    mysql_select_db("a6188092") or die(mysql_error());
        
                    if (isset (
    $_COOKIE['loginName']))
                    {
                        
    $query mysql_query(sprintf("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'"mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' mysql_error());
                    
                        if (
    $query)
                            {
                                
    $message "Your ride has been deleted.";
                            }
            
                        else
                        {
                            
    $message "Ride not deleted updated.";
                        } 
                    }
                }
                echo 
    "$message";
                
    ?>
    Thanks.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,174
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    It's not necessarily an error.

    It is *NOT* an error to specify a DELETE or UPDATE to a db that turns out to not remove or change any records. It's just PHP reporting to you that, indeed, no records were deleted/changed. If that's okay with you, just ignore the message.


  •  

    Posting Permissions

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