0

I've basically been researching this Uncaught Error: Call to a member function bind_param() on bool error I've been getting for the last 2 hours with nothing.

$post_data = json_decode(file_get_contents("php://input"));
$encoded_publisher = base64_encode($post_data->publisher);
$encoded_notes = base64_encode($post_data->notes);
$rellevel = $post_data->releaselevel;
$uid = $post_data->uid;

$request = $db->prepare('UPDATE release_history SET author = ?, notes = ?, release_state = ? WHERE uid = ?');
                                                $request->bind_param('ssss', $encoded_publisher, $encoded_notes, $rellevel, $uid);

All these fields are checked at the start of the script if they're empty and they all have data, I've also checked if the data is valid and it is

I've tried changing the MySQL statement, changed the variable names, changed the parameter values like ssss -> ssssssss, I've tagged out every line except the prepare and bind_param lines and its the same error, I've also run the code on the MySQL server and it works perfectly fine

The script should simply update the database entry but it just gives an error

Beth
  • 1
  • Your call to `prepare()` failed. Either check the return value for validity and get the error message if invalid, or set mysqli to throw exceptions on error, which would be preferable as it save having to write boilerplate code constantly. – Sammitch Dec 13 '22 at 23:46
  • `researching ...for the last 2 hours with nothing`... [really](https://www.google.com/search?q=Uncaught+Error%3A+Call+to+a+member+function+bind_param()+on+bool) ??? – ADyson Dec 13 '22 at 23:47
  • Duplicate of: [What to do with mysqli problems? Errors like mysqli\_fetch\_array(): Argument #1 must be of type mysqli\_result and such](https://stackoverflow.com/questions/22662488/what-to-do-with-mysqli-problems-errors-like-mysqli-fetch-array-argument-1-m) . Half the results in my first link would have led you to that anyway. Basically: enable mysqli error reporting so you can get the underlying SQL error message which caused the prepare to fail. Then you can find out what's _actually_ wrong with your query instead of doing random guess-and-hope changes to your code forever. – ADyson Dec 13 '22 at 23:48
  • (The error you get now is basically because you haven't enabled mysqli error reporting, and when prepare() fails then [as per the documentation](https://www.php.net/manual/en/mysqli.prepare.php) if mysqli errors are switched off it will return `false`, which of course is a bool. And you can't call a function on a bool, so hence the error message.) – ADyson Dec 13 '22 at 23:51

0 Answers0