I am trying to register a user. After user registration, a direct login to the system occurs. So basically I want to start a session after registering immediately.
But I cannot do this because the session variable is not set! This gives me a headache :(
Please help me..
Here's the insert code in the users table:
if(isset($_POST["register_btn"]))
{
extract(array_map("test_input", $_POST));
$md5pass=md5($password);
$m->set_data('full_name',$full_name);
$m->set_data('gender',$gender);
$m->set_data('email',$email);
$m->set_data('mobile',$mobile);
$m->set_data('password',$md5pass);
$m->set_data('created_date',$date);
$m->set_data('updated_date',$date);
$a1= array ('role_id'=> 2,
'full_name'=> $m->get_data('full_name'),
'gender'=> $m->get_data('gender'),
'email'=> $m->get_data('email'),
'mobile'=> $m->get_data('mobile'),
'password'=> $m->get_data('password'),
'created_date' => $m->get_data('created_date'),
'updated_date' => $m->get_data('updated_date'));
$last_auto_id=$d->last_auto_id("users");
$res=mysqli_fetch_array($last_auto_id);
$user_id=$res['Auto_increment'];
$insert=$d->insert('users',$a1);
if($insert>0)
{
$_SESSION['user_id']=$user_id;
header("location:account.php?msg=Your account has been created.");
}
else {
header("location:account.php?msg=Error.");
}
}
Now, if I try to print $ _SESSION ['user_id'] in the code below:
<?php
extract(array_map("test_input", $_GET));
if(isset($msg)) {
echo $msg . "<br/>";
echo "Welcome, ".$_SESSION['user_id'] ;
}
?>
He gives me the conclusion:
Your account has been created.
Note: Undefined index: user_id in C: \ xampp \ htdocs \ maxosale_client \ account.php on line 30 Welcome,
I wrote session_start () in the header and is included in this code above so that there is no problem.
So here is my problem, please help me.