Jump to content

MySQL DB update via PHP script fails with SQLSTATE[42000] error, y? How to fix?


sigkill-9

Recommended Posts

I'm a beginner to PHP and MySQL and need some help figuring out why my php script is giving me "SQLSTATE[42000]" errors when I try to update a MySQL database.

 

I have a php form that allows an administrator to reset certain fields in a MySQL movies database. When the admin pushes a form button, that button calls the following function to update the database:

	function reset_rental_fields() {
	try {
		if(!self::$dbh) $this->connect();
		$sql  = "UPDATE tblMovies SET avail=1;UPDATE tblMovies SET userID='';UPDATE tblMovies SET dueDate='';UPDATE tblMovies SET rentDate='';";
		$sth = self::$dbh->prepare($sql);
	}
	catch (PDOException $e) {
		$this->fatal_error($e->getMessage());
	}
	return $sth->execute();
}

 

When this function runs I get the "SQLSTATE[42000]" error, but, when I run the same query direclty from the "Run SQL query/queries on database" window in phpMyadmin it runs just fine...

 

Here is the query I run in phpMyadmin:

UPDATE tblMovies SET avail=1;UPDATE tblMovies SET userID='';UPDATE tblMovies SET dueDate='';UPDATE tblMovies SET rentDate='';

 

as you can see, same query sent from the PHP script. Now, when I seperate the above query into 3 seperate functions in my PHP script, I can run each update one by one successfully.

 

Can someone show me what I need to do to get the query to execute properly from the PHP script using just one function?

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.