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.

2
  • 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. Commented Sep 4, 2012 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? Commented Sep 4, 2012 at 16:23

2 Answers 2

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); 
Sign up to request clarification or add additional context in comments.

3 Comments

It is - I did a var_dump($stmt) and it is returning FALSE, so I'm at a loss because the statement appears correct.
Check $mysqli::error for the reason why.
I found the issue - I was missing a field on the INSERT - damn I hate when it's something so simple....
1

In response to your question you can do the following:

 INSERT INTO tableName (column1, column2, column3,...) VALUES (value1, value2, value3,...) 

2 Comments

There looks to be 7 to me, the first "variable" holds the field types.
Ah..thank you sir - I knew there was a way!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.