PHP Fatal error: Call to a member function bind_pa

2019-06-27 12:40发布

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 blank every single 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 is referring to the block of code above.

I am at my wits end with this, I have been trying to fix it for hours and it just won't work. I cannot find any problems with my sql query and I am losing my mind trying to figure out what's wrong.

标签: php mysqli
2条回答
Rolldiameter
2楼-- · 2019-06-27 13:20

It seems $statement = $mysqli->prepare(..) give result FALSE so $statement is not object and you can't use $statement->bind_param(..)

$statement = $mysqli->prepare("...");

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

PHP - MySQLi - prepare

BTW: Have you test your SQL query directly in database by copy/paste ?

查看更多
甜甜的少女心
3楼-- · 2019-06-27 13:41

Don't use MYSQL keywords in $mysqli->prepare,for example:from,select etc. So,your datatables fields name are important!Please checking

查看更多
登录 后发表回答