开发者

Database query failed

I keep getting a message back saying 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 'WHERE id=2' at line 1, and I can't seem to find the cause. My User insert method works fine, but for whatever reason, I can't get past this error with this update method:

public funct开发者_运维知识库ion update(){
  global $database;

  $sql  = "UPDATE users SET ";
  $sql .= "username='"   . $database->escape_value($this->username)   ."', "; 
  $sql .= "password='"   . $database->escape_value($this->password)   ."', "; 
  $sql .= "first_name='" . $database->escape_value($this->first_name) ."', "; 
  $sql .= "last_name='"  . $database->escape_value($this->last_name)  ."', "; 
  $sql .= "WHERE id="    . $database->escape_value($this->id); 
  $database->query($sql);
  if($database->affected_rows() == 1){
     $message = "success";

  }else{
     $message = "no " . mysql_error();
  }
  return $message;
}


The last comma before the WHERE clause is an error, change:

$sql .= "last_name='"  . $database->escape_value($this->last_name)  ."', "; 

to

$sql .= "last_name='"  . $database->escape_value($this->last_name)  ."' "; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜