SQL Upate query error

Associate
Joined
13 Nov 2003
Posts
1,567
Location
Manchester
Hi All

Can anyone see anything wrong with this query, been staring at it for ages but cant spot it, it will be something blatant

mysql_select_db($database_ebaytemplate, $ebaytemplate);
$query = "UPDATE templates VALUES SET 'title' = '$title', 'description' = '$description', 'refurbished' = '$refurbished', 'circ_id' = '$circ_id', 'picture_url' = '$picture_url'". "WHERE 'id' ='$id' LIMIT 1";
mysql_query($query, $ebaytemplate) or die(mysql_error());

The error is
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 'VALUES SET 'title' = 'title 2 2', 'description' = 'test', 'refur

Ta
AAron
 
fluiduk said:
Hi All

Can anyone see anything wrong with this query, been staring at it for ages but cant spot it, it will be something blatant

mysql_select_db($database_ebaytemplate, $ebaytemplate);
$query = "UPDATE templates VALUES SET 'title' = '$title', 'description' = '$description', 'refurbished' = '$refurbished', 'circ_id' = '$circ_id', 'picture_url' = '$picture_url'". "WHERE 'id' ='$id' LIMIT 1";
mysql_query($query, $ebaytemplate) or die(mysql_error());

The error is
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 'VALUES SET 'title' = 'title 2 2', 'description' = 'test', 'refur

Ta
AAron

You want the query to look like:

$query = "UPDATE templates (title, description, refurbished, circ_id, picture_url) VALUES SET ($title, $description, $refurbished, $circ_id, $picture_url) WHERE id =$id LIMIT 1";

If any of those variables correspond to text fields you need to quote e.g.

WHERE id =\'$id\' LIMIT 1";
 
No joy with that, still getting an 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 '(title, description, refurbished, circ_id, picture_url) VALUES
 
Ehm.. you're confusing the insert with the update statement.

Update <tablename> set <fieldname>=value[,<fieldname2>=value2]

or

Insert INTO <tablename> (fieldname1, fieldname2, ...) values (value1, value2,...)

hope this helps...
 
Remove the VALUES from your query, that's for INSERT statements:
Code:
$query = "UPDATE templates SET 'title' = '$title', 'description' = '$description', 'refurbished' = '$refurbished', 'circ_id' = '$circ_id', 'picture_url' = '$picture_url'". "WHERE 'id' ='$id' LIMIT 1";
 
I just realised you're doing an update not insert! Sorry, should read things properly - you just need to escape all the single quotes in the query:

SET \'title\' = \'$title\',
 
shine said:
I just realised you're doing an update not insert! Sorry, should read things properly - you just need to escape all the single quotes in the query:

SET \'title\' = \'$title\',
No, for the 4th time, he needs to remove the keyword VALUES and restructure his query to use the format as described by Augmented. You definitely need to read posts properly.
 
Thanks for that Augmented, sadly I am still getting an 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 ''title' = 'title 2 2', 'description' = 'desc 2xcvbcvbcvbcvb', 'r
 
Dj_Jestar said:
No, for the 4th time, he needs to remove the keyword VALUES and restructure his query to use the format as described by Augmented. You definitely need to read posts properly.

You're right I do. :) However Augemented's query isn't right either. it should be:

Code:
$query = "UPDATE templates SET title = '$title', description = '$description', refurbished = '$refurbished', circ_id = '$circ_id', picture_url = '$picture_url'". "WHERE id ='$id' LIMIT 1";

field name don't need to be quoted. We'll get there in the end! :D
 
Back
Top Bottom