PHP Fatal error: call member function bind_param () on an object without an object

I have the following code:

$statement = $mysqli->prepare("INSERT INTO `paypal_transactions` (`txn_id`, `payer_email`, `mc_gross`, `mc_currency`, `expires`, `userid`) VALUES (?, ?, ?, ?, " . (time() + 2678400) . ", ?)"); file_put_contents('error.txt', $mysqli->error . mysqli_error($mysqli)); $statement->bind_param('ssdsi', $txn_id, $payer_email, $payment_amount, $payment_currency, $userid); $statement->execute(); 

error.txt is empty every time, and this is what I see in the error_log file:

 [02-Jul-2013 09:08:15 America/Denver] PHP Fatal error: Call to a member function bind_param() on a non-object in /home4/site/public_html/paypal.php on line 96 

which refers to the code block above.

I am on my way with this, I tried to fix it for hours, and it just won't work. I can not find any problems with my SQL query, and I lose consciousness, trying to understand what is wrong.

+4
source share
2 answers

It seems that $statement = $mysqli->prepare(..) gives the result FALSE , so $statement not an object, and you cannot use $statement->bind_param(..)

 $statement = $mysqli->prepare("..."); if( $statement !== FALSE ) { $statement->bind_param(...); $statement->execute(); } 

PHP - MySQLi - prepare

BTW: Did you check your SQL query directly in the database by copying / pasting?

+3
source

Do not use MYSQL keywords in $ mysqli-> prepare, for example: from, select, etc. Therefore, the name of the fields of your data is important! Check out

0
source

Source: https://habr.com/ru/post/1489305/


All Articles