purencool Posted October 12, 2009 Share Posted October 12, 2009 I have been looking at this code for 20mins and can't work out what I am doing wrong. There is something wrong with my sql statement below is the error and the code. what I am trying to do is to edit some information that is already in the database Any help would be great. 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 'active=1 content='dafasdsdfasgbvfgf gasd' at line 3 private function insertq() { if ( !empty($this->pageName) && !empty($this->position) && !empty($this->content) ) { echo $this->pageName ." pn<br>"; echo $this->position ." pos<br>"; echo $this->content." con<br>"; echo $this->active." act<br>"; $query = "UPDATE webContent SET myOrder =$this->position active=$this->active content='$this->content' WHERE pageName = '$this->pageName'"; if (mysql_query($query)) { echo("<P>Your update has been added.</P>"); } else { echo("<P>Error adding submitted update: " . mysql_error() . "</P>"); } } return $returnValue; } Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/ Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 Please change echo("<P>Error adding submitted update: " . mysql_error() . "</P>"); to echo("<P>Error adding submitted update: " . mysql_error() . ": $query</P>"); This will display full query string, so that we might look at it and try to find out what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935642 Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2009 Share Posted October 12, 2009 SET expects a comma separated list - myOrder =$this->position, active=$this->active, content='$this->content' Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935644 Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 Good one Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935647 Share on other sites More sharing options...
purencool Posted October 12, 2009 Author Share Posted October 12, 2009 I tried it with the commas still did not work. Below the following error came up with the change error handler Error adding submitted update: 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 ' content='dafasdsdfasgbvfgf gasdasdfsdfsd' at line 3: UPDATE webContent SET myOrder =5, active= , content='dafasdsdfasgbvfgf gasdasdfsdfsdfsdf', WHERE pageName = 'ffdadfadfsadfsdfsdfas' Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935649 Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 In your query you can see: active= , which means $this->active is not set. Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935660 Share on other sites More sharing options...
purencool Posted October 12, 2009 Author Share Posted October 12, 2009 yes I thought that to when I saw it but Error adding submitted update: 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 'WHERE pageName = 'ffdadfadfsadfsdfsdfas'' at line 5: UPDATE webContent SET myOrder =5, active=1 , content='dafasdsdfasgbvfgf gasdasdfsdfsdfsdf', WHERE pageName = 'ffdadfadfsadfsdfsdfas' Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935665 Share on other sites More sharing options...
Mchl Posted October 12, 2009 Share Posted October 12, 2009 Too much commas. There should be no comma before WHERE Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935672 Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2009 Share Posted October 12, 2009 And in reply#4 you did not have a comma there (nor did anyone show putting one there.) Why did it get added? Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935674 Share on other sites More sharing options...
purencool Posted October 12, 2009 Author Share Posted October 12, 2009 the short answer is I stuffed up thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/177453-solved-sql-error/#findComment-935683 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.