07-30-db/login.php
<?php
/* Using Session Variables */
session_start();
$error_msg = "";

/* Setup the Connection Parameters to the DB */
$host = "127.0.0.1";
$user = "nerdarmy";
$pass = "";
$db = "testDB";
$port = 3306;

/* make a connection to the mySQL database */
$connection = mysqli_connect($host, $user, $pass, $db, $port) 
    or die(mysql_error());

/* check the post data */

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

    /* Grab the user-entered log-in data */
    $userName = $_POST['userName'];
    $userPassword = $_POST['userPassword'];

    /* Does a record exist with these credentials */
    $query = "SELECT COUNT(*) AS total FROM Users WHERE ISADMIN=1 AND USERNAME='$userName' AND PASSWORD='$userPassword'";
    $result = mysqli_query($connection, $query);
    $row = mysqli_fetch_assoc($result);
    

    if ($row['total'] != 0) {

        $_SESSION['userID'] = $userName;
        $_SESSION['userName'] = $userName;
        
        setcookie('userID', $userName, time() + (60 * 60 * 24 * 30));    // expires in 30 days
        setcookie('userName', $userName, time() + (60 * 60 * 24 * 30));  // expires in 30 days
        
        // Redirect to the home page
        header('Location: userList.php');
        exit();
        
    } else {
        $error_msg = 'Sorry, you must enter a valid username and password to log in.';
    }
    
}
?>

<!doctype html>
<title>nerdArmy-3000 Login</title>
<style>
    #loginBox {
        width:400px;
        margin-left:auto;
        margin-right:auto;
        border: 4px solid grey;
        border-radius:10px;
        padding:10px;
    }
</style>

<form method="post" action="login.php">

<div id="loginBox">
    <table style="width:100%;">
        <tr>
            <td colspan="2"><b>Login</b></td>
        </tr>
        <tr>
            <td style="text-align:right;">Username:</td>
            <td><input type="text" name="userName" value="<?php echo $userName; ?>"></td>
        </tr>
        <tr>
            <td style="text-align:right;">Password:</td>
            <td><input type="password" name="userPassword"></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="Log In" name="submit"></td>
        </tr>
        <tr>
            <td colspan="2" style="font-size:10px; color:red;"><?php echo $error_msg; ?></td>
        </tr>
    </table>
</div>
</form>