Orionsbelter Posted April 23, 2011 Share Posted April 23, 2011 Hi i have the following code $orderFetch->order="3"; mysql_query("UPDATE `categories` SET order=order-1 WHERE `order` > $orderFetch->order"); i wish to minus -1 from all the "order" fields in categories that are over a certain value i.e 3. But however this code is not working can anyone tell me where i'm going wrong? thank you Link to comment https://forums.phpfreaks.com/topic/234502-taking-1-from-a-mysql-field-when-above-a-certain-value/ Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2011 Share Posted April 23, 2011 Add logic to check for query success/failure, and (at least while in development) echo the query string along with mysql_error() on failure. On success check that mysql_affected_rows() is > 0. Link to comment https://forums.phpfreaks.com/topic/234502-taking-1-from-a-mysql-field-when-above-a-certain-value/#findComment-1205185 Share on other sites More sharing options...
Orionsbelter Posted April 23, 2011 Author Share Posted April 23, 2011 it displays 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 'order=order-1 WHERE `order` > 3' at line 1 Link to comment https://forums.phpfreaks.com/topic/234502-taking-1-from-a-mysql-field-when-above-a-certain-value/#findComment-1205208 Share on other sites More sharing options...
Pikachu2000 Posted April 23, 2011 Share Posted April 23, 2011 `order` is a MySQL reserved word. Either change the name of the field, or enclose `order` in backticks whenever it appears in a query string as a field/table/database name. Link to comment https://forums.phpfreaks.com/topic/234502-taking-1-from-a-mysql-field-when-above-a-certain-value/#findComment-1205209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.