I've notice that when one of the two conditions in a php if statement is not true. You get an undefined index notice for the statement that is not true. And the result in my case is a distorted web page. For example, this code:
<?php
session_start();
if (!isset($_SESSION['loginAdmin']) && ($_SESSION['loginAdmin'] != '')) {
header ("Location: loginam.php");
} else {
include('head2.php');
}
if (!isset($_SESSION['login']) && ($_SESSION['login'] != '')) {
header ("Location: login.php");
} else {
include('head3.php');
}
?>
If one of the if statements is not true. The one that is not true will give you a notice that it is undefined. In my case it says that the session 'login' is not defined. If session 'LoginAdmin' is used. What can you recommend that I would do in order to avoid these undefined index notice.
EDIT This is where I check if the entered information is correct, for those who are asking. It always redirects to the login page even if the login information is correct:
$uname = mysql_real_escape_string($_POST['ausername']);
$pword = mysql_real_escape_string($_POST['apassword']);
$idnam= mysql_real_escape_string($_POST['aydi']);
$SQL = "SELECT * FROM admin WHERE ID= '$idnam' AND admin = '$uname' AND admin_password = '$pword'";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if ($result) {
if ($num_rows > 0) {
session_start();
$_SESSION['loginAdmin'] = "1";
header ("Location: ampage.php");
}
else {
session_start();
$_SESSION['loginAdmin'] = "";
header ("Location: loginam.php");
}
}
else {
$errorMessage = "Error logging on, please try again.";
}