i am currently having problem allowing user to login with both username or email and entered and matching it with the database, here is my code:
<?php
//Login Script
if (isset($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = $_POST["user_login"];
$password_login = $_POST["password_login"];
$md5password_login = md5($password_login);
$sql = mysqli_query($conn, "SELECT id FROM users2 WHERE username='$user_login' AND password='$md5password_login' LIMIT 1"); // query the person
//Check for their existance
$userCount = mysqli_num_rows($sql); //Count the number of rows returned
if ($userCount == 1) {
while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)) {
$rahul = $row["id"];
}
$_SESSION["id"] = $rahul;
$_SESSION["user_login"] = $user_login;
$_SESSION["password_login"] = $password_login;
exit("<meta http-equiv=\"refresh\" content=\"0; url=./home.php\">");
} else {
echo 'That information is incorrect, try again';
exit();
}
}
?>
i don't know what to add in the mysqli_query to allow user to login from both the username and email.
simple change your query like this
$sql = mysqli_query($conn, "SELECT id FROM users2 WHERE (username='$user_login' OR `email`='$user_login') AND password='$md5password_login' LIMIT 1"); // query the person
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments