smokyyyyyy Posted January 12, 2011 Share Posted January 12, 2011 im getting error when i run the page Database Query Failed: 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 '' at line 1 my query is public function update(){ global $db; $sql= "UPDATE user SET "; $sql.= "username='". $db->mysql_prep($this->username) ."', "; $sql.= "password='". $db->mysql_prep($this->password) ."', "; $sql.= "firstname='".$db->mysql_prep($this->firstname) ."', "; $sql.= "lastname='". $db->mysql_prep($this->lastname) ."' "; $sql.= "WHERE id=". $db->mysql_prep($this->id); $db->query($sql); return ($db->affected_rows()==1)?true:false; Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/ Share on other sites More sharing options...
mikosiko Posted January 12, 2011 Share Posted January 12, 2011 did you echo $sql; ?? what it shows? Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158547 Share on other sites More sharing options...
smokyyyyyy Posted January 12, 2011 Author Share Posted January 12, 2011 yeh i have echo its in query function $db->query() function takes sql command and run it n show result i guess there is problem in update statement Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158548 Share on other sites More sharing options...
mikosiko Posted January 12, 2011 Share Posted January 12, 2011 again... what echo $sql; shows Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158555 Share on other sites More sharing options...
smokyyyyyy Posted January 12, 2011 Author Share Posted January 12, 2011 i have echo query it shows this result Database Query Failed: 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 '' at line 1 Last Query: UPDATE user SET username='', password='jimmy', firstname='', lastname='pakistan' WHERE id= Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158562 Share on other sites More sharing options...
smokyyyyyy Posted January 12, 2011 Author Share Posted January 12, 2011 thsese are my functions public function update(){ global $db; $sql= "UPDATE user SET "; $sql.= "username='". $db->mysql_prep($this->username) ."', "; $sql.= "password='". $db->mysql_prep($this->password) ."', "; $sql.= "firstname='".$db->mysql_prep($this->firstname) ."', "; $sql.= "lastname='". $db->mysql_prep($this->lastname) ."' "; $sql.= "WHERE id=". $db->mysql_prep($this->id); $db->query($sql); return ($db->affected_rows()==1)?true:false; query function used in update function is public function query($sql){ $this->last_query= $sql; $result= mysql_query($sql,$this->connection); $this->confirm_query($result); return $result; confirm query function used in query is private function confirm_query($result){ if(!$result){ $output = "Database Query Failed: ". mysql_error()."<br/><br/>"; $output.= "Last Query: ". $this->last_query; die($output); } } error i got is Database Query Failed: 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 '' at line 1 Last Query: UPDATE user SET username='', password='jimmy', firstname='', lastname='pakistan' WHERE id= Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158576 Share on other sites More sharing options...
Pikachu2000 Posted January 12, 2011 Share Posted January 12, 2011 When posting code, please enclose it within the forum's . . . BBCode tags. Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158579 Share on other sites More sharing options...
mikosiko Posted January 13, 2011 Share Posted January 13, 2011 if this is the complete result of echo sql; Last Query: UPDATE user SET username='', password='jimmy', firstname='', lastname='pakistan' WHERE id= then the error that you are getting is correct because your sentence is incomplete... there is nothing after id= Link to comment https://forums.phpfreaks.com/topic/224226-update-query-problem-help-plz/#findComment-1158918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.