Login script stops

So when I try to login, it stops on the login tools page. Here is the login tools page:

<?php
require('uheader.php');
?>

<?php


if(isset($_POST['submit'])) {

$em = $_POST['email'];
$pa = $_POST['password'];



    $e = mysqli_real_escape_string($conn, trim($em));
    $p = mysqli_real_escape_string($conn, trim($pa));



    if (empty($e)) {
        echo "Please enter your Email<br>";
    } elseif (empty($p)) {
        echo "Please enter your password.<br>";
    } else {
        $q = "SELECT username FROM users WHERE email='$e' && password=SHA1('$p')";

        $r = mysqli_query($conn, $q);

        if (mysqli_num_rows($r) == 1) {
            $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
            return array(true, $row);

            $_SESSION['user'] = $row['username'];

            header("Location: home.php");


        } elseif(mysqli_num_rows($r) != 1) {
            echo "Email and password not found";
        }

        else{

        }
    }
}
?>

Nevermind I have figured it out

If your code is still even close to what you posted, you do not have it “figured out”. Also, SHA1 is way outdated. You need to use password_hash and password_verify. The return statement just plain doesn’t belong in the code.

I suggest you use PDO. https://phpdelusions.net/pdo

You can also download my PDO Bumpstart Database from my signature to get you going.

Here is a quick and dirty to get you in a better direction.

[php]<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
{
$error = [];

if (empty($_POST['email']))
    {
    $error['email'] = 'Email Required.';
    }

if (empty($_POST['password']))
    {
    $error['password'] = 'Password Required.';
    }

if ($error)
    {
    //Handle Errors;
    }
else
    {
    //Check Login Credentials
    }
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service