"how to use mysqli prepare statement to login with email or username (not pdo)?" Code Answer

5

your problem is probably not on

$login_stmt->bind_param('ss', $account, $account);

as you'd think.

this looks fine, unless your $_post['account'] is an array and not a single variable, which i doubt. in this case it will fail there. but your where statement and bindparam looks correct

however this is not correct :

$login_stmt->bind_result($password);

because you try to bind only one variable and you have 3 columns returned in your select statement (select username,password,email )

since you don't really need the email and username in your code, just change your query like this:

$login_query = 'select password from user where username = ? or email = ?';

and it should work

By aviran on March 29 2022

Answers related to “how to use mysqli prepare statement to login with email or username (not pdo)?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.