MySQLi Prepared Statement Query Issue
Posted
by Benjamin Flak
on Stack Overflow
See other posts from Stack Overflow
or by Benjamin Flak
Published on 2010-05-19T00:36:10Z
Indexed on
2010/05/19
0:40 UTC
Read the original article
Hit count: 308
I'm relatively new to MySQLi prepared statements, and running into an error. Take this code:
$user = 'admin';
$pass = 'admin';
if ($stmt = $mysqli->query("SELECT * FROM members WHERE username='$user' AND password='$pass'"))
{
echo $stmt->num_rows;
}
This will display "1", as it should.
This next piece of code though, returns "0":
$user = 'admin';
$pass = 'admin';
if ($stmt = $mysqli->prepare("SELECT * FROM members WHERE username=? AND password=?"))
{
$stmt->bind_param("ss", $user, $pass);
$stmt->execute();
echo $stmt->num_rows;
}
Any ideas why?
© Stack Overflow or respective owner