0

When I login the system I get an error. I tried to fix it bu using "email" instead of id but it does not work. I am new at PHP. How can I fixed this?

Notice: Undefined variable: id in C:\xampp\xAmmp\htdocs\project\index.php on line 161

index.php

...
<?php if ($id == $_SESSION['id'] ) { ?>
            <h4>
                <span style="font-family:\'Pacifico\', cursive;">Welcome, </span>
                <div class="btn-group">
                    <button type="button" class="btn btn-success dropdown-toggle"
                            data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <i class="glyphicon glyphicon-user"></i> <?php echo explode(' ', $_SESSION["name"])[0] ?> <span
                            class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
...

login.php

<?php

include('conn.php');

session_start();
$error = "";

//email entered by user
$email = mysqli_real_escape_string($link, $_POST['email']);

//password entered by user md5 method is used for password encryption
$password = md5(md5($_POST['email']) . $_POST['password']);

//Query to see whether user and password combination exists
$query = "SELECT * FROM users WHERE email = '$email' AND password = '$password' LIMIT 1";

if ($result = mysqli_query($link, $query)) {
    if ($row = mysqli_fetch_array($result)) {

            $_SESSION['name'] = $row['name'];
            $_SESSION['email'] = $row['email'];
            $_SESSION['dob'] = $row['dob'];
            if (isset($row['rest']))
                $_SESSION['rest'] = $row['rest'];
        } else {
        $error .= "User does not exists with that combination of email and password.<br />";
    }
} else {
    $error .= "User does not exists with that combination of email and password.<br />";
}

if ($error != "")
    echo '<div class="alert alert-danger alert-dismissible fade in" role="alert" style="margin-top: 20px">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                ' . $error . '</div>';
?>
Eda
  • 19
  • 4
  • Nowhere in the code do you define a variable called `$id`. What exactly do you expect `$id == $_SESSION['id']` to compare? – David Mar 07 '20 at 11:22
  • $_SESSION['id'] is not set in your codes and what is $id that you want to check with $_SESSION['id'] ? – ArashShiri Mar 07 '20 at 11:23

0 Answers0