I am trying to run an update query through php to a postgresql database. When i try to do that i get an error.
I tried changing the id = ?
to id = :id
but it didn't work
My update
function:
//update a student
public function updateStudent(){
$query = 'UPDATE ' . $this->table . ' ( name, course) VALUES ( :name, :course) WHERE id = ? ;';
$stmt = $this->conn->prepare($query);
$this->id = htmlspecialchars(strip_tags($this->id));
$this->name = htmlspecialchars(strip_tags($this->name));
$this->course = htmlspecialchars(strip_tags($this->course));
$stmt->bindParam(':id', $this->id);
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':course', $this->course);
if($stmt->execute()){
return true;
}
//print error
printf("Error: %s.
", $stmt->error);
return false;
}
The error:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters in...
It says the error is on line 58 which is the line that reads:
$stmt = $this->conn->prepare($query);
I the error is within the line above 58.
Update:
If i use id = :id
instead of id = ?
, i get the following error:
Fatal error: Uncaught PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "(" LINE 1: UPDATE students ( name, course) VALUES ( $1, $2) WHERE id = ... ^ in