So, I am currently trying to make a login form for my browser game, which requires multiple queries to work properly. I first started with the normal procedure of querying using PHP and MySQL but soon discovered it wasn't the best way to do it because of SQL injection.
So, I decided to use the stmt, which according to stackoverflow, is safer.
My code is bigger than this, but I will just put here the part that is bugging (I have debugged the rest of the code and everything else is fine, including connection to the MySQL server)
$stmt = mysqli_prepare($conn, "SELECT username FROM users WHERE username='$playername'");
´
//Im pretty sure this is where the bug is
mysqli_stmt_bind_param($stmt, "s", $playername);
//----------------------------------------
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $dbusername);
mysqli_stmt_fetch($stmt);
$row_cnt = mysqli_stmt_num_rows($stmt);
if($row_cnt === 0) {
mysqli_stmt_close($stmt);
$error = true;
$errorid = "There is no player registered with that username.";
echo $errorid;
}
I have created an entry in the database with the username "Syvered" which is the one i am testing at the moment, and when trying to use that username on the login form (notice that $playername is the inputed username by the user) it still says "There is no such user with that username" which means that mysqli_stmt_num_rows($stmt) is returning 0 for some reason. This is what I dont understand.
I really hope I have been clear enough to you, thank you in advance for your help.
Questions I checked but unfortunately didn't help: