Hello
I am doing a project in PHP and recently facing a problem. I made a login and signup page using PHP, Mysqli. Sign up is working just fine. However, when logging in it is showing error=emptyinput even though I double checked and tried logging in using the recent data I stored 5s sooner. Can anyone help me with a solution?
Here's my code:
//login.php
<pre><!-- Login Box Start -->
<div class="popUpLogin">
<div class="blackBox activate"></div>
<div class="wrapper activate">
<div class="title">
Login Form
<button onclick=" enableActivate() ">×</button>
</div>
<form action="includes/login.inc.php" method="post">
<div class="field">
<input type="text" name="name" required>
<label>Email Address</label>
</div>
<div class="field">
<input type="password" name="pwd" required>
<label>Password</label>
</div>
<div class="content">
<div class="checkbox">
<input type="checkbox" id="remember-me">
<label for="remember-me">Remember me</label>
</div>
<div class="pass-link">
<a href="#">Forgot password?</a>
</div>
</div>
<div class="field">
<input type="submit" name="submit" value="Login">
</div>
<div class="signup-link">
Not a member? <a href="signup.php">Signup now</a>
</div>
</form>
</div>
<?php
if(isset($_GET["error"])){
if($_GET["error"] == "emptyinput"){
echo "<p>Fill in all feilds!</p>";
} else if($_GET["error"] == "wronglogin") {
echo "<p>Incorrent Login Information</p>";
}
}
?>
</div>
<!-- Login Box END -->
//login.inc.php
<pre>
<?php
if(isset($_POST["submit"])){
$username = $_POST["uid"];
$pwd = $_POST["pwd"];
require_once 'dbh.inc.php';
require_once 'functions.inc.php';
if(emptyInputLogin($username, $pwd) !== false){
header("location: ../logintest.php?error=emptyinput");
exit();
}
loginuser($conn, $username, $pwd);
} else {
header("location: ../logintest.php");
exit();
}
//functions.inc.php
function emptyInputLogin($username, $pwd){
$result;
if(empty($username) || empty($pwd)){
$result = true;
} else {
$result = false;
}
return $result;
}
function loginuser($conn, $username, $pwd) {
$uidExists = uidExists($conn, $username, $username);
if($uidExists === false){
header("location: ../logintest.php?error=wronglogin");
exit();
}
$pwdHashed = $uidExists["usersPwd"];
$checkPwd = password_verify($pwd, $pwdHashed);
if ($checkPwd === false){
header("location: ../logintest.php?error=wronglogin");
exit();
} else if ($checkPwd === true){
session_start();
$_SESSION["userid"] = $uidExists["usersID"];
$_SESSION["useruid"] = $uidExists["usersUid"];
header("location: ../index.php");
exit();
}
}
What I have tried:
I have tried logging in with recent username and password and searched google but I could not figure it out.