【发布时间】:2016-01-09 03:52:20
【问题描述】:
我有一个问题,我想将表单数据从“home.php”传输到“dashboard.php”,但在这里我检查了dashboard.php 上的会话以进行登录会话,如下所示:-
<?php
session_start();
?>
<?php
if(!$_SESSION["UserName"])
{
//Do not show protected data, redirect to login...
header('Location: login.php');
}
?>
当用户从“home.php”提交表单数据时,如果未生成登录会话,他将被重定向到登录页面进行登录。 在主页上,我使用 POST 方法形成如下:-
<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>
登录页面上的代码:-
<?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>";
}
}
?>
将“home.php”的数据显示到“dashboard.php”的代码
<?php echo $_POST["name_"]; ?>
</br> </br>
<?php echo $_POST["subject_"]; ?>
</br> </br>
<?php echo $_POST["message_"]; ?>
</br> </br>
登录后,用户可以访问dashboard.php,但我的问题是,当用户登录后,我从“home.php”获取的输入数据显示错误,如下图链接:-
[1]: http://i.stack.imgur.com/G5Udj.png
在完成上述表单数据处理后出现错误 --> 如果没有会话则登录 --> 仪表板
注意:未定义索引:C:\xampp\htdocs\youngants\dashboard.php 第 401 行中的 name_
注意:未定义索引:C:\xampp\htdocs\youngants\dashboard.php 第 403 行中的 subject_
注意:未定义索引:C:\xampp\htdocs\youngants\dashboard.php 第 405 行中的 message_
注意:未定义索引:C:\xampp\htdocs\youngants\dashboard.php 第 408 行中的名称
伙计们,我需要你的帮助,我如何通过会话变量将数据从“home.php”传输到“dashboard.php”,在表单提交后用户被重定向到登录然后返回到仪表板后,该变量甚至可以保持填充状态登录后的.php。
需要更多信息,请评论我会提供。
【问题讨论】:
-
请在此处发布错误。有些人无法访问图片托管网址。
-
@devlincarnate 我已经发布了问题中的错误,请查看。
标签: php mysql forms session post