I've recently updated from normal statements
$result = mysql_query("SELECT user_id from users WHERE user_id = '$user_id'");
to prepared statements(security)
prepare("SELECT user_id FROM users WHERE user_id = ?");
I followed some tutorials, but this still won't work:
public function isUserRegistered($user_id) {
print $user_id;
$stmt = $this->conn->prepare("SELECT user_id FROM users WHERE user_id = ?");
$stmt->bind_param("s", $user_id);
if ($stmt->execute()) {
$stmt->bind_result($user_id);
$stmt->fetch();
$no_of_rows = $stmt->num_rows;
print $no_of_rows;
$stmt -> close();
if ($no_of_rows > 0) {
print "Finally";
// user already registered
return true;
} else {
print "Stupid";
// user is not registered
return false;
}
}
}
The supplied id exists, because I can see it in the console being printed. The if ($stmt->execute())
is being executed, but for some reason nothing comes back.
How can I solve this and how can I print the result?
I've also tried:
while ($stmt->fetch()) {
printf ("%s (%s)
", $user_id);
}