sigkill-9 Posted March 14, 2009 Share Posted March 14, 2009 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? Link to comment https://forums.phpfreaks.com/topic/149428-mysql-db-update-via-php-script-fails-with-sqlstate42000-error-y-how-to-fix/ Share on other sites More sharing options...
sigkill-9 Posted March 14, 2009 Author Share Posted March 14, 2009 Nevermind, figured it out myself... UPDATE tblMovies SET avail=1, userID='', dueDate='', rentDate=''; Link to comment https://forums.phpfreaks.com/topic/149428-mysql-db-update-via-php-script-fails-with-sqlstate42000-error-y-how-to-fix/#findComment-784870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.