将用户名获取到另一个数据表

时间:2017-02-28 11:53:10

标签: php database

我有两个数据表,如 用户 问题 ,用于登录页面和信息页面   登录时我重定向做信息页面,我在提交后输入数据我希望将此登录用户名输入到该问题数据表中,请帮助我

登录页面如下

<?php  
session_start();  

?>  

<html>  
<head lang="en">  
   <meta charset="UTF-8">  
   <link type="text/css" rel="stylesheet" href="bootstrap-3.2.0-dist\css\bootstrap.css">  
   <title>Login</title>  
</head>    
<body>  


<div class="container">  
    <div class="row">  
    <div class="col-md-4 col-md-offset-4">  
        <div class="login-panel panel panel-success">  
            <div class="panel-heading">  
                <h3 class="panel-title">Sign In</h3>  
            </div>  
            <div class="panel-body">  
                <form role="form" method="post" action="login.php">  
                    <fieldset>  
                        <div class="form-group"  >  
                            <input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>  
                        </div>  
                        <div class="form-group">  
                            <input class="form-control" placeholder="Password" name="pass" type="password" value="">  
                        </div>  


                            <input class="btn btn-lg btn-success btn-block" type="submit" value="login" name="login" >   
                    </fieldset>  
                </form>  
            </div>  
            </div>  
     </div>  
    </div>  
</div>  


</body>  

</html>  

<?php  

include("db_conection.php");  

if(isset($_POST['login']))  
{  
    $user_email=$_POST['email'];  
    $user_pass=$_POST['pass'];  

  $check_user="select * from users WHERE user_email='$user_email'AND user_pass='$user_pass'";  

    $run=mysqli_query($dbcon,$check_user);  

    if(mysqli_num_rows($run))  
    {  
    echo "<script>window.open('welcome.php','_self')</script>";  

    $_SESSION['email']=$user_email;  

  }  
    else  
    {  
    echo "<script>alert('Email or password is incorrect!')</script>";  
    }  
}  
?>  

inner data page

   <?php  
session_start();    
if(!$_SESSION['email'])  
{  

  header("Location: login.php"); 
} 

if(isset($_POST['submit'])){
header("Location: feedback.php");
exit;
} 
?>  

<html>  
<head>  

    <title>  
    Registration  
    </title>  
</head>  

<body>  
<h1>Welcome</h1><br>  
<?php  
echo $_SESSION['email'];  
?>  
<form action="profile.php" method="post">
<input type='submit' name='submit' value='Give Us Your Feedback' class='register' />
</form>
<h1><a href="logout.php">Logout here</a> </h1>  
</body>  
</html> 

        data page

<?php
session_start();
include("config.php");
if(isset($_POST['submit']))
{
$answer1=$_POST['answer1'];
$answer2=$_POST['answer2'];
$answer3=$_POST['answer3'];
$answer4=$_POST['answer4'];
$answer5=$_POST['answer5'];
$answer6=$_POST['answer6'];

$insert=mysqli_query($conn,"insert into question(ans1,ans2,ans3,ans4,ans5,ans6)values('$answer1','$answer2','$answer3','$answer4','$answer5','$answer6')");
if($insert==TRUE)

{

header("Location:thanks.html");

}

}


?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Feedback Form</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">
<META http-equiv="Content-Type" content="text/html; charset=utf-8"></head>

<body>
<h3>Feedback Form</h3>
<div class="container">
<div class="row">
<div class="col-md-8 well">

<form class="sky-form" name="answer" method="post">

<div class="panel panel-default">

    <ul class="list-group">
        <li class="list-group-item">
            <div class="row toggle" id="dropdown-detail-1" data-toggle="detail-1">
                <div class="col-xs-10">
                    How did you contact technical support?
                </div>
                <div class="col-xs-2"><i class="fa fa-chevron-down pull-right"></i></div>
            </div>
            <div id="detail-1">
                <hr></hr>
                <div class="container">
                    <div class="fluid-row">
                        <div class="radio">

      <input type="radio" name="answer1"  id="a1" value="In Person"><label for="a1">In Person </label> <br>
    <input type="radio" name="answer1" id="a2" value="Over the Telephone"><label for="a2">Over the Telephone </label><br>
    <input type="radio" name="answer1" id="a3" value="Via Email"><label for="a3">Via Email</label><br>
    <input type="radio" name="answer1" id="a4" value="Via Internet Chat"><label for="a4">Via Internet Chat </label>
    </div>

                    </div>
                </div>
            </div>
        </li>

        <li class="list-group-item">
            <div class="row toggle" id="dropdown-detail-2" data-toggle="detail-2">
                <div class="col-xs-10">
                    Overall, how would you rate the process for getting your problem resolved?
                </div>
                <div class="col-xs-2"><i class="fa fa-chevron-down pull-right"></i></div>
            </div>
            <div id="detail-2">
                <hr></hr>
                <div class="container">
                    <div class="fluid-row">
                        <div class="radio">
    <input type="radio" name="answer2"  id="b1" value="Very Good"><label for="b1">Very Good </label> <br>
        <input type="radio" name="answer2" id="b2" value="Good"><label for="b2">Good </label><br>
        <input type="radio" name="answer2" id="b3" value="Average"><label for="b3">Average</label><br>
        <input type="radio" name="answer2" id="b4" value="Poor"><label for="b4">Poor </label><br>
      <input type="radio" name="answer2" id="b5" value="Very Poor"><label for="b5">Very Poor </label>

    </div>
                    </div>
                </div>
            </div>
        </li>

        <li class="list-group-item">
            <div class="row toggle" id="dropdown-detail-3" data-toggle="detail-3">
                <div class="col-xs-10">
                 About how long did you have to wait before speaking to a technical support representative?
                </div>
                <div class="col-xs-2"><i class="fa fa-chevron-down pull-right"></i></div>
            </div>
            <div id="detail-3">
                <hr></hr>
                <div class="container">
                    <div class="fluid-row">
                        <div class="radio">
      <input type="radio" name="answer3"  id="c1" value="I was taken care of immediately"><label for="c1">I was taken care of immediately </label> <br>
      <input type="radio" name="answer3" id="c2" value="Within 10 minutes"><label for="c2">Within 10 minutes</label><br>
    <input type="radio" name="answer3" id="c3" value="Between 10 to 30 minutes"><label for="c3">Between 10 to 30 minutes</label><br>
          <input type="radio" name="answer3" id="c4" value="Between 30 minutes to an hour"><label for="c4">Between 30 minutes to an hour</label><br>
   <input type="radio" name="answer3" id="c5" value="More than 1 hour"><label for="c5">More than 1 hour</label>
        </div>
                    </div>
                </div>
            </div>
        </li>

        <li class="list-group-item">
            <div class="row toggle" id="dropdown-detail-4" data-toggle="detail-4">
                <div class="col-xs-10">
                    About how long did you have to wait before your issue was resolved?
                </div>
                <div class="col-xs-2"><i class="fa fa-chevron-down pull-right"></i></div>
            </div>
            <div id="detail-4">
                <hr></hr>
                <div class="container">
                    <div class="fluid-row">
                        <div class="radio">
      <input type="radio" name="answer4"  id="d1" value="Within 2 hours"><label for="d1">Within 2 hours</label> <br>
      <input type="radio" name="answer4" id="d2" value="Between 2 to 4 hours"><label for="d2">Between 2 to 4 hours</label><br>
      <input type="radio" name="answer4" id="d3" value="Between 4 to 8 hours"><label for="d3">Between 4 to 8 hours</label><br>
      <input type="radio" name="answer4" id="d4" value="Between 8 to 12 hours"><label for="d4">Between 8 to 12 hours</label><br>
      <input type="radio" name="answer4" id="d5" value="More than 12 hours"><label for="d5">More than 12 hours</label>
    </div>
                    </div>
                </div>
            </div>
        </li>

        <li class="list-group-item">
            <div class="row toggle" id="dropdown-detail-5" data-toggle="detail-5">
                <div class="col-xs-10">
                The Technical Support Representative was knowledgeable?                    
                </div>
                <div class="col-xs-2"><i class="fa fa-chevron-down pull-right"></i></div>
            </div>
            <div id="detail-5">
                <hr></hr>
                <div class="container">
                    <div class="fluid-row">
                        <div class="radio">
      <input type="radio" name="answer5"  id="e1" value="Strongly Agree"><label for="e1">Strongly Agree</label> <br>
      <input type="radio" name="answer5" id="e2" value="Agree"><label for="e2">Agree</label><br>
      <input type="radio" name="answer5" id="e3" value="Neutral"><label for="e3">Neutral</label><br>
      <input type="radio" name="answer5" id="e4" value="Disagree"><label for="e4">Disagree</label><br>
      <input type="radio" name="answer5" id="e5" value="Strongly Disagree"><label for="e5">Strongly Disagree</label>
    </div>
                    </div>
                </div>
            </div>
        </li>

        <label for="title">Please share any additional comments about your experience or suggestions on how we can better improve our technical support services.</label>
        <textarea class="form-control"  rows="3" name="answer6" maxlength="250">
        </textarea>
</ul>
<div  id="my_centered_buttons">
    <button  type="submit" name="submit" value="submit">Submit</button>
</div>

</form>
</div>
</div>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:3)

当您登录时,我认为您必须将用户信息存储到会话中,您可以直接从会话中获取用户信息,包括用户名。