Fer Cervantes Fer Cervantes - 1 year ago 76
PHP Question

Can't get bind_param() working correctly

I'm trying to do a simple insert on my database after retrieving a value from it, I'm following the same procedure to retrieve a value from my database as to insert values in it, but I get the following error:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean

Here's my code:

$getuid = $mysqli->prepare("SELECT id FROM members WHERE email = ?");
$getuid->bind_param("s", $email);
$nombre = $_POST['nombre'];
$direccion = $_POST['direccion'];
$codpost = $_POST['codpost'];
$municipio = $_POST['municipio'];
$estado = $_POST['estado'];
echo("INSERT INTO infoclientes VALUES ($uid, $nombre, $direccion, $codpost, $municipio, $estado)");
$infocte = $mysqli->prepare("INSERT INTO infoclientes VALUES(?, ?, ?, ?, ?, ?)");
$infocte->bind_param("ssssss", $uid, $nombre, $direccion, $codpost, $municipio, $estado);

Apparently, the error comes out from

$infocte->bind_param("ssssss", $uid, $nombre, $direccion, $codpost, $municipio, $estado);

This is the output from the echo before the second bind_param:

INSERT INTO infoclientes VALUES (1, Fernando Cervantes, Av. Pie de la cuesta 2, 76158, Querétaro, Querétaro)

Answer Source

I got it to work! I just moved $getuid->close() to the line before the echo(). I guess it was as @LouisLoudogTrottier mentioned, I was trying to prepare both queries while the same connection was opened.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download