I have a issue where I want to transfer form data from "home.php" to "dashboard.php", but here i have a check of session on dashboard.php for login session as below:-
<?php
session_start();
?>
<?php
if(!$_SESSION["UserName"])
{
//Do not show protected data, redirect to login...
header('Location: login.php');
}
?>
here when a user submits a form data from "home.php" he gets redirected to login page for login if session of login is not generated. where as on homepage i have use POST method to form as below:-
<form class="form ajax-contact-form" method="POST" action="dashboard.php">
<div class="alert alert-success hidden" id="contact-success">
<span class="glyphicon glyphicon-ok "></span>
<strong>Success!</strong> Thank you for your message.
</div>
<div class="alert alert-danger hidden" id="contact-error">
<span class="glyphicon glyphicon-remove "></span>
<strong>Error!</strong> Oops, something went wrong.
</div>
<div class="row col-p10">
<div class="col-sm-6">
<label class="mb10">
<input type="text" name="name_" id="name_" required class="form-control" placeholder=" Full Name * ">
</label>
</div>
<div class="col-sm-6">
<label class="mb10">
<input type="text" name="subject_" id="subject_" required class="form-control" placeholder=" Subject *">
</label>
</div>
</div>
<div class="row col-p10">
<div class="col-sm-6">
<label class="mb10">
<input type="text" name="phone_" id="phone_" class="form-control" placeholder=" Phone">
</label>
</div>
<div class="col-sm-6">
<label class="mb10">
<input type="email" name="email_" id="email_" required class="form-control" placeholder=" Email Address *">
</label>
</div>
</div>
<label>
<textarea name="message_" id="message_" cols="30" rows="10" required class="form-control" placeholder=" Message *"></textarea>
</label>
<div class="mb40"></div>
<div class="clearfix">
<!-- Enter your google site key here for captcha -->
<div class="pull-right xs-pull-left xs-box">
</div>
<div class="pull-left">
<button type="submit" class="btn btn-icon btn-e" value="submit" name="submit"><i class="icon icon_mail_alt"></i> Sumbit</button>
<?php
if (isset($_POST['submit'])) {
$_SESSION['name_'] = $_POST['name_'];
$_SESSION['subject_'] = $_POST['subject_'];
}
?>
</div>
</div>
</form>
Code on Login page :-
<?php
include("connection.php");
session_start();//session starts here
?>
<?php
if(isset($_SESSION["UserName"]))
{
//Do not show protected data, redirect to login...
header('Location: dashboard.php');
}
?>
<?php
if(isset($_POST['login']))
{
$username=$_POST['Username'];
$user_pass=$_POST['password'];
$encrypt_pass = md5($user_pass);
$check_user="select * from tbl_logindetails WHERE UserName='".$username."' AND Password='".$encrypt_pass."'";
$run=mysqli_query($connection,$check_user);
if(mysqli_num_rows($run))
{
//echo "<script>window.open('www.google.com','_self')</script>";
header("Location: dashboard.php");
$_SESSION['UserName']= $username; //here session is used and value of $user_email store in $_SESSION.
}
else
{
echo "<script>alert( 'Error in Registering Useer, Please try again later' )</script>";
}
}
?>
Code to Display data of "home.php" to "dashboard.php"
<?php echo $_POST["name_"]; ?>
</br> </br>
<?php echo $_POST["subject_"]; ?>
</br> </br>
<?php echo $_POST["message_"]; ?>
</br> </br>
After Login the user gets access to dashboard.php, but my issue is when the user comes after doing the login the input data that i took from "home.php" shows an error as below attached image link:-
[1]: http://i.stack.imgur.com/G5Udj.png
Error i am getting after doing the above process of form data --> login if no session --> Dashboard
Notice: Undefined index: name_ in C:\xampp\htdocs\youngants\dashboard.php on line 401
Notice: Undefined index: subject_ in C:\xampp\htdocs\youngants\dashboard.php on line 403
Notice: Undefined index: message_ in C:\xampp\htdocs\youngants\dashboard.php on line 405
Notice: Undefined index: name in C:\xampp\htdocs\youngants\dashboard.php on line 408
Guys I need your help where how can i carry the data from "home.php" to "dashboard.php" by sessions variable which can even stay filled after the user is redirected to login after form submit and then returns to dashboard.php after login.
Any more information needed please comment i will provide it.