I have this mysqli prepared statement in PHP
if (isset($_POST['u']) && isset($_POST['p'])) {
$username = $_POST['u'];
$password = $_POST['p'];
$stmt = $conn->stmt_init();
$stmt = $conn->prepare("SELECT id FROM users WHERE username=? AND password=?");
$stmt->bind_param("ss",$username,$password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($uid);
if ($stmt->num_rows > 0) {
$_SESSION["login"] = 1;
$_SESSION["uid"] = $uid;
echo $uid;
}
$stmt->close();
}
It is echoing "0" when it should show 2, as I am logging into the account whose user id is 2. I have tested the statement with phpMyAdmin, and it is properly returning the correct user id number.
Any help would be awesome and educational, thanks.
BTW I know I am vulnerable to SQL Injections here. I will fix that after I figure this out.