#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Update query problem


    I'm getting the following error when I run the following update query from php

    Invalid query UPDATE `testing`.`reference` SET `position` = '17' WHERE `reference`.`id` = 120:

    `position` is VARCHAR and `id` is INT

    The code is

    $sql = "UPDATE `testing`.`reference` SET `position` = '17"
    . "' WHERE `reference`.`id` = 120";
    $update = mysql_query($sql,$conn);


    The query runs fine from phpMyAdmin, in fact the above code was created in phpMyAdmin but I can't see what the problem might be caused by. Maybe a new set of eyes can spot something obvious.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    You can call mysql_error() too get the error message.
    What happens if you remove all ` around the table and fields name:
    Code:
    UPDATE testing.reference SET position = '17' WHERE reference.id = 120:
    Just so you know, you should use PDO instead of mysql_query.
    More information can be found at the manual for [phpnet=mysql-query]mysql-query[/phpnet]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by MrFujin
    You can call mysql_error() too get the error message.
    What happens if you remove all ` around the table and fields name:
    Code:
    UPDATE testing.reference SET position = '17' WHERE reference.id = 120:
    Just so you know, you should use PDO instead of mysql_query.
    More information can be found at the manual for [phpnet=mysql-query]mysql-query[/phpnet]
    The error message was from mysql_error.

    if (!$update){
    die("Invalid query $sql: " . mysql_error());
    }

    Omitting the ` made no difference.
    I'll have a look at PDO but I can't see it making a difference, this is a very basic query.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by daveclucas
    The error message was from mysql_error.

    if (!$update){
    die("Invalid query $sql: " . mysql_error());
    }

    Omitting the ` made no difference.
    I'll have a look at PDO but I can't see it making a difference, this is a very basic query.
    After a night's sleep I immediately spotted the problem, I had commented out the query to check the data would be correct before updating the table but I forgot to comment out the error trapping.

IMN logo majestic logo threadwatch logo seochat tools logo