Skip to content
Advertisement

Login takes me to the same login form and does not login when entered the correct username and password

I made a login floating form. Whenever I try to login using the correct username and password it takes me to the login form but this time in a simple design and to another page. When I try to login from there nothing happens. Can anyone help me with this?

//logintest.php

<div class="popUpLogin">
<div class="blackBox activate"></div>
<div class="wrapper activate">
    <div class="title">
        Login Form
        <button onclick=" enableActivate() ">&times;</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" 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.inc.php

<?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 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();
    }
    }

In my header.php:

<div class="nav">
    <?php
        if(isset($_SESSION["useruid"])){
            echo "<a href='index.php' class='login' style='color: rgba(47, 128, 237, 
            1);'>Profile</a>";
        } else {
            echo "<button onclick='disableActivate()' class='login' style='color: rgba(47, 
            128, 237, 1);'>Login</button>";
            echo "<button onclick='document.location='signup.php' ' class='navSignup'> Get 
            your free card!</button>";
        }
        ?>
        </div>
        <?php
        include 'logintest.php';
        ?>
        <script>
        function disableActivate() {
        document.querySelectorAll(".wrapper")[0].classList.remove("activate");
        document.querySelectorAll(".blackBox")[0].classList.remove("activate");
        }

        function enableActivate() {
        document.querySelectorAll(".wrapper")[0].classList.add("activate");
        document.querySelectorAll(".blackBox")[0].classList.add("activate");
        }
        </script>

Advertisement

Answer

Normally for this event to happen, is after the form has been submitted.

What I see in the code provided could be that you forgot to assign a name for your button. What you need to do is:

HTML:

  <input type="submit" name="login" value="Login">

login.inc.php:

  if (isset($_POST['login'])){
      #login
  }else{
      #deny access
   }

In compiling this code, the browser runs the code and searches for a button called login, and then takes action

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement