Jump to content

update query problem help plz


smokyyyyyy

Recommended Posts

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

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=

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=

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=

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.