- 11 months ago 55
PHP Question

How to fix undefined index: after unsetting a variable

Please I have been trying to fix this but not working out right for me. I have a session started but after logging out using

, I am unable to login back as it's showing this error:

Notice: Undefined index: emaill in C:\xampp\htdocs\buth_net\nursingSchool\login.php on line 7.

Please help me out. Note: I am getting the error message after unsetting the variable.
//this is login.php

$msg = "";
if (isset($_POST['login'])){
include "dbconnect.php";
if($_SESSION['emaill'] !== NULL){
$emaill= $_SESSION['emaill'];
$passWord = $_POST['passWord'];
if (empty($emaill && $passWord) == false){
$sql = "SELECT * FROM `sono` WHERE `eMail`='$emaill' && `passWord`='$passWord'";
$check = mysqli_query($dbconnect, $sql) or die (mysqli_error($dbconnect));
$result = mysqli_num_rows($check);
if ($result > 0){
$emaill= $_SESSION['emaill'];
header ('location: home.php');
} else
$msg = "<p style='color: red; padding-left: 10px'>Invalid password or email address</p>";
} else
$msg = "<p style='color: red; padding-left: 10px'>Please enter your email and password to login</p>";
} else
$msg = "<p style='color: red; padding-left: 10px'>My scripts not working yet</p>";

// this is for logout
if (isset($_SESSION['emaill'])){
header('location: login.php');


before using $_SESSION['emaill'], check it with isset() like :

if( isset($_SESSION['emaill']) && $_SESSION['emaill'] !== NULL){