4

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.

BenR
  • 11,296
  • 3
  • 28
  • 47
user2543204
  • 43
  • 1
  • 4
  • Do you have a permission to write to error.txt? Why not to make it into the same `error_log` with `trigger_error()` instead of inconvenient `file_put_contents(`? – Your Common Sense Jul 02 '13 at 15:57
  • where does $mysqli variable come from? I think it is not an object or other put, it does not have value which is suppose to have. – Hossein Baghayi Jul 02 '13 at 16:14
  • I'm having the same problem. `var_dump($statement);` is telling me it's an instance of `object(mysqli_stmt)` but `bind_param()` is still failing with that message. – Jeremy List Nov 19 '14 at 03:23

2 Answers2

3

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 ?

furas
  • 134,197
  • 12
  • 106
  • 148
0

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

Praise Song
  • 187
  • 2
  • 2