Jump to content

Recommended Posts

<?php 

session_start();


// if(empty($_POST['email'])||empty($_POST['password'])||empty($_POST['cat']))
// {
//     echo "You must enter all fields";
// }
if($_POST['cat']=='Employee')
{

    include_once "include.php";
    if (isset($_POST['submit'])) {
    $ee_email = $_POST['email'];
    $ee_email = stripslashes($_POST['email']);
    $ee_email = strip_tags($ee_email);
    $ee_email = mysql_real_escape_string($ee_email);
    $ee_password = $_POST['password']; 
    $ee_password = md5($ee_password);



    $sql = "SELECT * FROM employees WHERE ee_email= '".$ee_email."' AND ee_password= '".$ee_password."'"; 
    $res = mysql_query($sql) or die(mysql_error());
    $login_check = mysql_num_rows($res);
    if($login_check == 1){ 
    while($row = mysql_fetch_array($res)){ 
        $ee_id = $row["ee_id"];   
        session_register('ee_id'); 
        $_SESSION['ee_id'] = $ee_id;
        $ee_email = $row["ee_email"];
        session_register('ee_email'); 
        $_SESSION['ee_email']= $ee_email;
        $ee_fname = $row["ee_fname"];
        session_register('ee_fname'); 
        $_SESSION['ee_fname']= $ee_fname;
        $ee_lname = $row["ee_lname"];
        session_register('ee_lname'); 
        $_SESSION['ee_lname']= $ee_lname;
        

        
    }  


}


        // header("location: index.php"); 
        // exit();
}    
else {
        print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br />
        <br /><a href="login.php">Click here</a> to go back to the login page.';
  // exit();
    }
}

     
    
if($_POST['cat']=='Employer')
{


   include_once "include.php";

    if (isset($_POST['submit'])) {
    $er_email = $_POST['email'];
    $er_email = stripslashes($_POST['email']);
    $er_email = strip_tags($er_email);
    $er_email = mysql_real_escape_string($er_email);
    $er_password = $_POST['password']; 
    $er_password = md5($er_password);


    $sql1 = "SELECT * FROM employers WHERE er_email= '".$er_email."' AND er_password= '".$er_password."'"; 
    $res1 = mysql_query($sql1) or die(mysql_error());
    $login_check1 = mysql_num_rows($res1);
    if($login_check1 == 1){ 
    while($row1 = mysql_fetch_array($res1)){ 
        $er_id = $row1["er_id"];   
        session_register('er_id'); 
        $_SESSION['er_id'] = $er_id;
        $er_email = $row1["er_email"];
        session_register('er_email'); 
        $_SESSION['er_email']= $er_email;
        $er_fname = $row1["er_fname"];
        session_register('er_fname'); 
        $_SESSION['er_fname']= $er_fname;
        $er_lname = $row1["er_lname"];
        session_register('er_lname'); 
        $_SESSION['er_lname']= $er_lname;
        
        
    }  

}

        // header("location: index.php"); 
        // exit();
}
else {
        print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br />
        <br /><a href="login.php">Click here</a> to go back to the login page.';
  // exit();
    }
}

?>

Why it is showing error Undefined Index....???

Link to comment
https://forums.phpfreaks.com/topic/297707-undefined-index-in-session-variable/
Share on other sites

the error is self explanatory, it means that you are referencing an array index that doesn't exist.

 

since the only reference to an array index by that name is in this line - $er_id = $row1["er_id"];, does your database table have a column named er_id?

 

also, why do you have two database tables, one for employees and one for employers, and double the amount of code? that's not how to program. the visitors that are logging in shouldn't need to pick which type they are on the form page. all they should need to do is enter their email and password. it should be up to your single database table and your code to know what type they are. by having two tables, you are have to write, test, and debug double the amount of code for the form and for the form processing.

 

lastly, the mysql_ database functions are obsolete and will be removed from php in the near future. you should be learning to use either the PDO or mysqli_ database functions so that what you are learning isn't already out of date.

Perhaps you could point out the line that is giving you the error message since line 99 in your post is blank.

 

No need to get indignant - you were simply asked for a more complete details to help solve your dilemma.

 

PS - if you removed all the uses of session_register, what did you replace them with? Perhaps you could post your revised code - specifically the area where you are having the problem?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.