1

Possible Duplicate:
Call to a member function bind_param() on a non-object

I'm getting the following error:

Call to a member function bind_param() on a non-object

Here's the prepared statement:

include('/path/to/connection/variable.php');

This file is verified to be working it's just creates an instance of the mysqli class, example:

$mysqli = new mysqli("localhost", "user", "password", "db");

So I know that's not the issue...

$stmt = $mysqli->prepare("INSERT INTO `users` VALUES (?,?,?,?,?,?,?)");
$stmt->bind_param("sssssss", $firstname, $lastname, $email, $subscribed, $signup_date, $unsubscribe_date, $signup_source);
$stmt->execute();
$stmt->close();
$mysqli->close();

Variable types are as follows:

$firstname = string
$lastname = string
$email = string
$subscribed = char (Y or N)
$signup_date = DATE - date('Y-m-d')
$unsubscribe_date = DATE - 0000-00-00 Entered Initially
$signup_source = string

I've tried to find all the usual suspects, checked the connection, basically I wrote a separate SELECT statement and it works. "USERS" is a valid table. Permissions for the connection are root, so that's not the issue. I've switched the types for dates between "s" and "d", and even tried everything with dummy variables - no difference.

I'm hoping it's something simple - because I've been racking my brain for the past hour now, and I can't see anything wrong with the statement above.

Community
  • 1
  • 1
William Orazi
  • 1,694
  • 6
  • 23
  • 36
  • Yea - I'm receiving `FALSE` on `var_dump($stmt)`, which is what's confusing me, because the statement has the correct syntax, it's a correct table, and the field count is correct, etc. – William Orazi Sep 04 '12 at 16:20
  • Edit: I found the issue - I was missing a field on the INSERT - damn I hate when it's something so simple.... On a related since I'm not the best with mySQL is there a way I can target INSERT for only a couple fields - i.e. exclude trailing fields in the statement? – William Orazi Sep 04 '12 at 16:23

2 Answers2

4

That usually means your ->prepare() call has failed, and returned a boolean FALSE instead of statement object. Check for that:

$stmt = $mysqli->prepare("INSERT INTO `users` VALUES (?,?,?,?,?,?,?)") or die($mysqli::error);
Marc B
  • 356,200
  • 43
  • 426
  • 500
1

In response to your question you can do the following:

 INSERT INTO tableName (column1, column2, column3,...) 
 VALUES (value1, value2, value3,...)
DaOgre
  • 2,080
  • 16
  • 25