1

I hate to ask this question but I have searched and searched and done all sorts of things to see if I can resolve on my own.

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

var_dump = bool(false)

$stmt = $mysqli->prepare("INSERT INTO resetPswd (userID,key,date,status) VALUES (?,?,NOW(),0)");

$stmt->bind_param('is', $userID,$key);

$stmt->execute();

I have removed everything then added all back the problem lies with "key", it works until I add that in.

I am creating a random 'key':

 $key = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);

db = key - varchar(12)

Any help would be great! Why am I using mysqli? It's required.

harkly
  • 87
  • 1
  • 12

3 Answers3

4

KEY is a reserved word in MySQL.

You must escape it with backticks in order to use it as column name.

$stmt = $mysqli->prepare("INSERT INTO resetPswd (userID,`key`,date,status)  
                          VALUES (?,?,NOW(),0)");
Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
0

That error means that the call to $mysqli->prepare returned something that isn't an object, my guess would be it returns something like "false" which is not an object and thus you can't call "bind_param" on false. Doesn't sound like $key has anything to do with it.

in need of help
  • 1,606
  • 14
  • 27
0

From the PHP documentation:

If the database server successfully prepares the statement, PDO::prepare() returns a PDOStatement object. If the database server cannot successfully prepare the statement, PDO::prepare() returns FALSE or emits PDOException (depending on error handling).

http://php.net/manual/en/pdo.prepare.php#refsect1-pdo.prepare-returnvalues

You have an error in your query. key is a reserved word and will make that statement return false

devpro
  • 16,184
  • 3
  • 27
  • 38
vsmoraes
  • 194
  • 2
  • 7