herghost Posted March 8, 2010 Share Posted March 8, 2010 Hi all, Whats the correct way of putting this statement? $query ="UPDATE customers SET (title, forename, surname, company, nameno, fline, sline, city, state, zip, country, tax, email, phone, fax, username, password, newsletter) VALUES ('$title', '$forename', '$surname', '$company', '$nameno', '$fline', '$sline', '$city', '$state', '$zip', '$country', '$tax', '$email', '$phone', '$fax', '$username', '$password', '$newsletter') WHERE id = '$id';" Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/ Share on other sites More sharing options...
cags Posted March 8, 2010 Share Posted March 8, 2010 Define correct, are you saying that doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/#findComment-1023042 Share on other sites More sharing options...
herghost Posted March 8, 2010 Author Share Posted March 8, 2010 Sorry, yes this does not work, I am getting 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, forename, surname, company, nameno, fline, sline, city, state, zip, coun' at line 2 Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/#findComment-1023051 Share on other sites More sharing options...
Anti-Moronic Posted March 8, 2010 Share Posted March 8, 2010 I'm thinking it is likely you are using a mysql reserved keyword in one of you column names. Check the mysql manual to be sure. If you are, just change them and try again. This is one THE most annoying errors. Had it a once and spent days trying to resolve it because of that absolutely useless error feedback. Here's a link: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html --- and this is my lack of knowledge coming out - but can you even use an update query in that format? My understanding was it had to be structured like this: $result = mysql_query("UPDATE example SET age='22',field2='val2',field3='val3' WHERE age='21'") Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/#findComment-1023053 Share on other sites More sharing options...
PFMaBiSmAd Posted March 8, 2010 Share Posted March 8, 2010 That's not the syntax for an UPDATE query - UPDATE [LOW_PRIORITY] [iGNORE] table_reference SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/#findComment-1023056 Share on other sites More sharing options...
herghost Posted March 8, 2010 Author Share Posted March 8, 2010 Hi, Thanks, So it should look like: update customers set forename=$forename, surname=$surname where id='$id' ? Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/#findComment-1023059 Share on other sites More sharing options...
Anti-Moronic Posted March 8, 2010 Share Posted March 8, 2010 Yeh, but make sure you enclose the updated values with ' ': update customers set forename='$forename', surname='$surname' where id='$id' Quote Link to comment https://forums.phpfreaks.com/topic/194511-update-help-whats-the-correct-way/#findComment-1023063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.