php 命令没有将我移动到下一页

标签 php mysql mysqli xampp

我正在尝试创建一个页面,用户在其中输入 secret 问题,然后单击“下一步”导航到下一个问题。我尝试检查我的代码,但找不到任何问题。请帮忙! Secret_Question1.php

<?php
    session_start();
    error_reporting(1);
    if(isset($_SESSION['tempsagauser']))
    {
        $connection = mysqli_connect('localhost','root','','uni-saga');
    if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
        $user=$_SESSION['tempsagauser'];
        $que1=mysqli_query($connection,"select * from users where Email='$user' ");
        $rec=mysqli_fetch_array($que1);
        $userid=$rec[0];
        $gender=$rec[4];
        $que2=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");
        $count1=mysqli_num_rows($que2);
        if($count1==0)
        {

            $que3=mysqli_query($connection,"select * from user_profile_pic where user_id=$userid");
            $count3=mysqli_num_rows($que3);
            if($count3>0)
            {
?>
<?php
    if(isset($_POST['Next']))
    {
        $que1=$_POST['que'];
        $ans1=$_POST['ans'];

        mysqli_query("insert into user_secret_quotes(user_id,Question1,Answer1) values('$userid','$que1','$ans1')");
        header("location:../saga_step3/Secret_Question2.php");
    }
?>
<html>
<head>
    <title> Step2 </title>
<?php
    include("step2_background/background.php");
?>
    <link href="step2_css/step2.css" rel="stylesheet" type="text/css">
    <link href="../../saga_font/font.css" rel="stylesheet" type="text/css">
    <LINK REL="SHORTCUT ICON" HREF="../../saga_title_icon/saga-logo.jpg" />
    <script src="step2_js/que_check.js" language="javascript">
    </script>
</head>
<body>

<form method="post" name="sq" onSubmit="return check()">

<div style="position:absolute; left:33.5%; top:43%;"> <h3> Secret Question 1: </h3> </div>

<div style="position:absolute; left:45%; top:45%;">
<select name="que" style="height:38;font-size:18px;padding:3;">
        <option value="select one">select one</option>
        <option value="what is the first name of your favorite uncle?">what is the first name of your favorite uncle?</option>
        <option value="where did you meet you spouse?">where did you meet you spouse?</option>
        <option value="what is your oldest cousins name?">what is your oldest cousin's name?</option>
        <option value="what is your youngest childs nickname?">what is your youngest child's nickname?</option>
        <option value="what is your oldest childs nickname?">what is your oldest child's nickname?</option>
        <option value="what is the first name of your oldest niece?">what is the first name of your oldest niece?</option>
        <option value="what is the first name of your oldest nephew?">what is the first name of your oldest nephew?</option>
        <option value="what is the first name of your favorite aunt?">what is the first name of your favorite aunt?</option>
        <option value="where did you spend you honeymoon?">where did you spend you honeymoon?</option>
</select>
</div>

<div style="position:absolute; left:35.8%; top:52.7%;"> <h3> Your Answer:  </h3> </div>
<div style="position:absolute; left:45%; top:55%;">  <input type="text" name="ans" / style="height:35; width:350; font-size:18px;" maxlength="50">   </div>

<div style="position:absolute; left:45%; top:67%;"> <input type="submit" name="Next" value="Next" id="Next_button" > </div>

</form>

<div style=" position:absolute; left:16%; top:42%;"> <img src="img/waiting.gif"> </div>

<?php
        include("step2_erorr/step2_erorr.php");
?>
</body>
</html>
<?php
            }
            else
            {
                if($gender=="Male")
                {
                    header("location:../saga_step1/Step1_Male.php");
                }
                else
                {
                    header("location:../saga_step1/Step1_Female.php");
                }
            }
        }
        else
        {
            header("location:../saga_step3/Secret_Question2.php");
        }
    }
    else
    {
        header("location:../../../index.php");
    }
?>

Secret_Question2.php

<?php
    session_start();
    error_reporting(1);
    if(isset($_SESSION['tempsagauser']))
    {
        $connection = mysqli_connect('localhost','root','','uni-saga');
    if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
        $user=$_SESSION['tempsagauser'];
        $que1=mysqli_query($connection,"select * from users where Email='$user' ");
        $rec=mysqli_fetch_array($que1);
        $userid=$rec[0];
        $que2=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");
        $rec2=mysqli_fetch_array($que2);
        $q2=$rec2[3];
        $a2=$rec2[4];
        if($q2=="" && $a2=="")
        {
            $que3=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");
            $count3=mysqli_num_rows($que3);
            if($count3>0)
            {

?>
<?php
    if(isset($_POST['Finish']))
    {
        $que2=$_POST['que'];
        $ans2=$_POST['ans'];

        mysqli_query($connection,"update user_secret_quotes set Question2='$que2',Answer2='$ans2' where user_id=$userid");

        $que_user_data=mysqli_query($connection,"select * from users where Email='$user';");
        $user_data=mysqli_fetch_array($que_user_data);
        $userid=$user_data[0];
        $user_join_time=$user_data[6];
        mysqli_query($connection,"insert into user_post(user_id,post_txt,post_time,priority) values($userid,'Join UniSaga','$user_join_time','Public');");
        mysqli_query($connection,"insert into user_status values($userid,'Online')");
        mysqli_query($connection,"insert into user_info(user_id) values($userid)");

        session_start();
        $_SESSION['sagauser']=$user;
        header("location:../../saga_home/Home.php");
    }
?>
<html>
<head>
    <title> Step3 </title>
<?php
    include("step3_background/background.php");
?>
    <link href="step3_css/step3.css" rel="stylesheet" type="text/css">
    <link href="../../saga_font/font.css" rel="stylesheet" type="text/css">
    <LINK REL="SHORTCUT ICON" HREF="../../saga_title_icon/Faceback.ico" />
    <script src="step3_js/que_check.js" language="javascript">
    </script>
</head>
<body>

<form method="post" name="sq" onSubmit="return check()">

<div style="position:absolute; left:33.5%; top:43%;"> <h3> Secret Question 2: </h3> </div>

<div style="position:absolute; left:45%; top:45%;">
<select name="que" style="height:38;font-size:18px;padding:3;">
        <option value="select one">select one</option>
        <option value="what was your favorite food as a child?">what was your favorite food as a child?</option>
        <option value="what was the last name of your first boss?">what was the last name of your first boss?</option>
        <option value="what is the name of your favorite sports team?">what is the name of your favorite sports team?</option>
        <option value="what was you first pets name?">what was you first pet's name?</option>
        <option value="what is the name of your favorite book?">what is the name of your favorite book?</option>
        <option value="who is your all-time favorite movie character?">who is your all-time favorite movie character?</option>
        <option value="what was the make of your fist car?">what was the make of your fist car?</option>
        <option value="what was the make of your first motorcycle?">what was the make of your first motorcycle?</option>
        <option value="who is you favorite author?">who is you favorite author?</option>
</select>
</div>

<div style="position:absolute; left:35.8%; top:52.7%;"> <h3> Your Answer:  </h3> </div>
<div style="position:absolute; left:45%; top:55%;">  <input type="text" name="ans" / style="height:35; width:350; font-size:18px;" maxlength="50">   </div>

<div style="position:absolute; left:45%; top:67%;"> <input type="submit" name="Finish" value="Finish" id="Next_button" > </div>

</form>

<div style=" position:absolute; left:16%; top:42%;"> <img src="img/waiting.gif"> </div>

<?php
        include("step3_erorr/step3_erorr.php");
?>

</body>
</html>
<?php
            }
            else
            {
                header("location:../saga_step2/Secret_Question1.php");
            }
        }
        else
        {
            header("location:../../saga_home/Home.php");
        }
    }
    else
    {
        header("location:../../../index.php");
    }
?>

最佳答案

希望它有效!

  <?php
    /* Redirect to a different page in the current directory that was requested */
    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'mypage.php';
    header("Location: http://$host$uri/$extra");
    exit;
    ?>

关于php 命令没有将我移动到下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44298062/

相关文章:

php - laravel 构造函数重定向

php - 存储过程调用后 Codeigniter DB 错误

php - 将 mysql 转换为 mysqli

php - 如何使用 bind_result 与 get_result 的示例

php - 处理数据库中的标签

php - Symfony,getters 和 setters 与魔术方法

mysql - 如何根据select结果插入mysql表

php - 正确使用bind_param?

php - 多次循环 jQuery .post 函数

php - 使用 where 语句在多列上选择不同的值