Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
Richard MacCutchan 13-Jun-21 3:25am    
Where is the uid field on the login form?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900