0

Hello All firstly I would like to thank you for your time, I am having to do this for college (web server scripting unit p4) this is my simple log in but cannot get it up and running keep getting the error message: Notice: Undefined index: username in C:\xampp\htdocs\index.php on line 4

Here is my code:

<?php
session_start();

if($_POST["username"]) {

    $dbUsname = "Stephen";
    $dbPassword = "Password123";
    $uid = "0001";

    $usname = strip_tags($_POST["username"]);
    $pass = strip_tags($_POST["password"]);

    if (username == $dbUsname && $pass == $dbPassword) {
        $_SESSION["username"] = $usname;
        $_SESSION["id"] = $uid;
        header("Location; user.php");
        } else {
            echo"<h2>UH OH Oh no you didnt your password was incorrect.
            <br> /> Enter that again.</h2>";
        }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Login System</title>
<style type="text/css">
html {
    font-family: Verdano, Genevo, sans-serif;
}
h1{
    font-size: 24px;
    text-align: center;
}
#wrapper {
    position: absolute;
    width: 100px;
    top: 30%;
    margin-top: -50%;
}
#form {
    margin: auto;
    width: 200px;
    height: 100px
}
</style>
</head>

<body>
<div id="wrapper">
<h1>Login</h1>
<form id="form" action="index.php" method="post" enctype="multiport/form-data">
Username: <input type="text" name="username" /> <br> />
Password: <input type="password" name="password" /> />
<input type="submit" value="Login" name="Submit" />
</form>
</body>
</html>  
stephenconlon
  • 1
  • 1
  • 1
  • 2

1 Answers1

0

$_POST might not have any index named "name". Use isset($_POST["name"]) to check if the index exists.

eric.m
  • 1,577
  • 10
  • 20