Mysql $query = Update $variable field quick php question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkx
    Confirmed User
    • Nov 2003
    • 4001

    #1

    Mysql $query = Update $variable field quick php question

    First time using the update command.

    Basically trying to change the status from 1 to 2 which works with this query without the $id variable I inserted. Anyone know how I format the $id variable properly in this query?


    mysql_select_db($mysql);
    $query = 'UPDATE `sms`.`messages_import` SET `timestamp` = NOW(), `status` = \'2\' WHERE `messages_import`.`id` = `"$.id."` LIMIT 1;';


    Again I tried a few common variations that I knew of like $id, '$id', etc but nothing seemed to work

    Mucho appreciatedo
  • grumpy
    Too lazy to set a custom title
    • Jan 2002
    • 9870

    #2
    Code:
    mysql_select_db($mysql);
    $query = 'UPDATE `sms`.`messages_import` SET `timestamp` = NOW(), `status` = \'2\' WHERE `messages_import.id` = `".$id."` LIMIT 1;';
    its ".$id."
    Last edited by grumpy; 12-17-2009, 12:50 AM.
    Don't let greediness blur your vision | You gotta let some shit slide
    icq - 441-456-888

    Comment

    • mkx
      Confirmed User
      • Nov 2003
      • 4001

      #3
      Originally posted by grumpy
      Code:
      mysql_select_db($mysql);
      $query = 'UPDATE `sms`.`messages_import` SET `timestamp` = NOW(), `status` = \'2\' WHERE `messages_import.id` = `".$id."` LIMIT 1;';
      its ".$id."
      Thanks got it working with '.$id.'

      Comment

      • darksoul
        Confirmed User
        • Apr 2002
        • 4997

        #4
        thats a pretty fugly style with all those escapes. The only escape you need is for timestamp which is a reserved keyword
        Code:
        $query = "UPDATE sms.messages_import SET `timestamp` = NOW, status=2 WHERE messages_import.id=$id";
        You also don't need LIMIT 1, since the id is unique (in most cases anyway)
        1337 5y54|)m1n: 157717888
        BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
        Cambooth

        Comment

        • redwhiteandblue
          Bollocks
          • Jun 2007
          • 2793

          #5
          When you are running queries you're not sure of, always use this format for the query call (assuming you're using the old style mysql calls):

          $result = mysql_query($query) or die(mysql_error() . ", query was $query");

          Then not only can you see what the error was, you can see why the query string caused it.
          Interserver unmanaged AMD Ryzen servers from $73.00

          Comment

          Working...