Web Analytics Made Easy -
StatCounter Syntax error from query?? - CodingForum

Announcement

Collapse
No announcement yet.

Syntax error from query??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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
    Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

    Comment


    • #3
      Removing the asterix just leaves me with this error message now -

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

      Comment


      • #4
        Im confused why its not working
        Post rest of your code.
        Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

        Comment


        • #5
          That means that the criteria you have given points to no record in your database, try checking your WHERE criteria...

          Comment


          • #6
            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.

            Comment


            • #7
              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.
              Be yourself. No one else is as qualified.

              Comment

              Working...
              X