September 6th, 2012, 06:02 PM
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.
September 6th, 2012, 06:43 PM
You can call mysql_error() too get the error message.
What happens if you remove all ` around the table and fields name:
Just so you know, you should use PDO instead of mysql_query.
UPDATE testing.reference SET position = '17' WHERE reference.id = 120:
More information can be found at the manual for [phpnet=mysql-query]mysql-query[/phpnet]
September 7th, 2012, 07:05 AM
The error message was from mysql_error.
Originally Posted by MrFujin
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.
September 7th, 2012, 07:28 AM
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.
Originally Posted by daveclucas