QuePID Posted May 30, 2011 Share Posted May 30, 2011 Hi, I am building an update query which will update a record in a table, but I am getting an error which doesn't make sense to me. Here is my code: $query = "UPDATE iknew SET ID='$id', SET Herbarium='$herbarium', SET Taxon='$taxon', SET Bar_Code='$bar_code', SET GUID='$guid', SET Private='$private', SET Image='$image', SET Kingdom='$kingdom', SET Genus='$genus', SET Species='$species', SET Variety_Name='$variety_name', SET Taxon_Author='$taxon_author', SET Accession='$accession', SET State='$state', SET County='$county', SET Habitat='$habitat', SET Locality='$locality', SET Latitude='$latitude', SET Longitude='$longitude', SET Quadrangle='$quadrangle', SET Collector='$collector', SET Collection_Number='$collection_number', SET Country='$country', SET Family='$family', SET Annotation='$annotation', SET Col_Date='$col_date', SET Comments='$comments', SET Natural_Area='$natural_area', SET Col_datet='$col_datet', SET Symbol='$symbol' WHERE ID='$id' LIMIT 1"; Here is a sample update query: UPDATE iknew SET ID='62547', SET Herbarium='EKY', SET Taxon='Salix exigua Nutt.', SET Bar_Code='3288', SET GUID='', SET Private='1', SET Image='', SET Kingdom='Plantae', SET Genus='Salix', SET Species='exigua', SET Variety_Name='', SET Taxon_Author='Nutt.', SET Accession='EKY3288', SET State='Kentucky', SET County='Madison', SET Habitat='stream bank', SET Locality='Hagan Mill Road at bridge over Silver Creek.', SET Latitude=' 0', SET Longitude=' 0', SET Quadrangle='', SET Collector='John Hornback', SET Collection_Number='38', SET Country='USA', SET Family='Salicaceae', SET Annotation='', SET Col_Date='1976-04-18', SET Comments='RRP', SET Natural_Area='', SET Col_datet='', SET Symbol='SAEX' WHERE ID='62547' LIMIT 1 And here is the error given: 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 'SET Herbarium='EKY', SET Taxon='Salix exigua Nutt.', SET Bar_Code='3288', SET' at line 3 Any help would be quite appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/237819-mysql-update-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2011 Share Posted May 30, 2011 The SET keyword is only use once in an update query statement. Quote Link to comment https://forums.phpfreaks.com/topic/237819-mysql-update-query/#findComment-1222114 Share on other sites More sharing options...
QuePID Posted May 30, 2011 Author Share Posted May 30, 2011 The SET keyword is only use once in an update query statement. I've tried it with a single SET and still gives the same error. Quote Link to comment https://forums.phpfreaks.com/topic/237819-mysql-update-query/#findComment-1222116 Share on other sites More sharing options...
fugix Posted May 30, 2011 Share Posted May 30, 2011 you will need to use one set and seperat the column name with commas...check here for correct syntax Quote Link to comment https://forums.phpfreaks.com/topic/237819-mysql-update-query/#findComment-1222117 Share on other sites More sharing options...
Muddy_Funster Posted May 30, 2011 Share Posted May 30, 2011 And assuming that ID field is an auto_inc integer - don't wrap it in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/237819-mysql-update-query/#findComment-1222218 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2011 Share Posted May 30, 2011 ^^^ Actually, you wouldn't want the id to appear in the SET term at all as it is the key value you are using to identify the data in the database table. Quote Link to comment https://forums.phpfreaks.com/topic/237819-mysql-update-query/#findComment-1222262 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.