2
I’m a beginner in PHP and I’m getting this error while trying to make a Insert in the database using Mysqli functions:
Fatal error: Call to a member function bind_param() on string in C:\xampp\htdocs\Uc16\cadastro.php on line 5
What I’m doing wrong?
$sql = "INSERT INTO tb_usuarios(user_nome,user_senha,user_nivel,user_cpf,user_end_rua,user_end_bairro,user_end_numero,user_tel,user_email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$sql->bind_param('ssisssiss',
$_POST['user_nome'],
$_POST['user_senha'],
$_POST['user_nivel'],
$_POST['user_cpf'],
$_POST['user_end_rua'],
$_POST['user_end_bairro'],
$_POST['user_end_numero'],
$_POST['user_tel'],
$_POST['user_email']);
if ($conn->query($sql) === TRUE) {
echo "Registrado";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
The
bind_param
can only be used in astmt
and not in a string. So the$sql
must be astmt
, for example amysqli_prepare()
.– Inkeliz