0

I've never gotten this unidentified index error until lately. My sign_in form :

    <div id="signIn">
    <h1>Sign In</h1>
   <form action="check2.php" method="POST" name="sign_in" id="sign_in" onSubmit="return validateForm2()">
   <input class="up_form" type="text" name="email" id="email" placeholder="Email" autoComplete="off"></br>
   <input class="up_form" type="password" name="password" id="password" placeholder="Password" autoComplete="off"></br>
   <input class="button" type="submit" name="submit_in" id="submit_in" value="Sign In">
   </form>
    </div>

The proceeding check2.php code:

 <?php
session_start();

$username = strip_tags($_POST['username']);
//get password
$password = md5($_POST['password']);

if(!empty($username) && !empty($password)) {

    $conn = mysqli_connect("localhost","root","") or die ("No SQLI");
            mysqli_select_db($conn, "sample") or die ("No DB");

    $email_check = mysqli_query($conn, "SELECT `email` FROM `users` WHERE `email` = '$email'");

    $pass_check = mysqli_query($conn, "SELECT `password` FROM `users` WHERE `password` = '$password'");

    $eCheck = mysqli_num_rows ($email_check);

    $passCheck = mysqli_num_rows($pass_check);

    if (($eCheck == 1) && ($passCheck == 1))    {

    $_SESSION['username'] = strip_tags($_POST['username']);
    $_SESSION['logged_in'] = '1';

    header('location:index.php');

    mysqli_close($conn);

} else {

    echo "Your info is incorrect";

    }

} else {

    echo "You must enter info";
}
?>

For the life of me I have no idea why I get this error >> "Undefined index: username in C:\wamp\www\splindr_2.0\check2.php on line 4" << I'm sure it's something extremely simple that I'm skipping.

ralston3
  • 53
  • 5

2 Answers2

0

You don't have any input in your form named "username". Fix that, and this particular error should go away.

Either omit this line:

$_SESSION['username'] = strip_tags($_POST['username']);

or add the input to the form in the HTML, it can be a hidden input if need be.

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
0

I do not see an input with a name of "username"

either omit this line:

$_SESSION['username'] = strip_tags($_POST['username']);

or add the input to the form in the HTML, it can be a hidden input if need be.

Smith Smithy
  • 585
  • 6
  • 24