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);
$getuid->execute();
$getuid->bind_result($uid);
$nombre = $_POST['nombre'];
$direccion = $_POST['direccion'];
$codpost = $_POST['codpost'];
$municipio = $_POST['municipio'];
$estado = $_POST['estado'];
while($getuid->fetch()){
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);
$infocte->execute();
$infocte->close();
}
$getuid->close();
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)
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.