Sessions and undefined index

Status
Not open for further replies.
A

Anonymous

Guest
I am trying to test my session variable for the code below, but when I F12 the script I get an undefined index error. I know this is to do with arrays:

I am assuming that this ['email'] is an array.
I have gone through the code and they are all the same as the textfield names. What am I doing wrong?

Code:
<?php // accesscontrol.php 
include_once 'common.php'; 
include_once 'db.php';

session_start();
//At this point, the user's login details should be available whether they were just submitted from a login form 
//(in the $_POST array) or stored in the user's session (in the $_SESSION array). 
//The script pulls the login credentials out of either the $_POST or the $_SESSION array:

$uid = isset($_POST['email']) ? $_POST['email'] : $_SESSION['email']; 
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];

if(!isset($uid)) { 
 ?> 
 <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 <html xmlns="http://www.w3.org/1999/xhtml"> 
 <head> 
 <title> Please Log In for Access </title> 
 <meta http-equiv="Content-Type" 
   content="text/html; charset=iso-8859-1" /> 
 </head> 
 <body> 
 <h1> Login Required </h1> 
 <p>You must log in to access this area of the site. If you are 
    not a registered user, <a href="signup.php">click here</a> 
    to sign up for instant access!</p> 
 <p><form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="log_frm" id="log_frm"> 
   User ID: <input name="email" type="text" id="email" size="8" /> 
   Password: <input name="pwd" type="password" id="pwd" SIZE="8" /> 
   <input type="submit" value="Log in" /> 
 </form></p> 
 </body> 
 </html> 
 <?php 
 exit; 
}
$_SESSION['email'] = $uid; 
$_SESSION['pwd'] = $pwd;

dbConnect("db1"); 
$sql = "SELECT * FROM users WHERE 
       Email = '$uid' AND Password = PASSWORD('$pwd')"; 
$result = mysql_query($sql); 
if (!$result) { 
 error('A database error occurred while checking your '. 
       'login details.\\nIfhis error persists, please '. 
       'contact trufla@trufla.com.'); 
}

if (mysql_num_rows($result) == 0) { 
 unset($_SESSION['email']); 
 unset($_SESSION['Pwd']); 

 ?> 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 <html xmlns="http://www.w3.org/1999/xhtml"> 
 <head> 
 <title> Access Denied </title> 
 <meta http-equiv="Content-Type" 
   content="text/html; charset=iso-8859-1" /> 
 </head> 
 <body> 
 <h1> Access Denied </h1> 
 <p>You do not have permission to access these pages.<br>
    Click <a href="self_service.php">here</a> to return to<br> 
	the self service point.</p> 
 </body> 
 </html> 
 <?php 
 exit; 
}

$username = mysql_result($result,0,'Firstname'); 
?>
 
Trufla, do not cross-post.

http://www.php-forum.com/p/viewtopic.php?t=4816

Locked.
 
Status
Not open for further replies.
Back
Top