php命令不会将我移动到下一页

Posted

技术标签:

【中文标题】php命令不会将我移动到下一页【英文标题】:php command not moving me to the next page 【发布时间】:2017-11-02 01:02:04 【问题描述】:

我正在尝试创建一个页面,用户可以在其中输入秘密问题,然后单击下一步以导航到下一个问题。我试图查看我的代码,但找不到任何问题。请帮忙! 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");
    
?>

【问题讨论】:

什么不起作用?导航到另一个页面?或者别的什么 是的,导航到另一个页面 【参考方案1】:

希望它有效!

  <?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;
    ?>

【讨论】:

我仍然收到解析错误->解析错误:语法错误,C:\xampp\htdocs\uni-saga\saga_files\saga_step\saga_step2\Secret_Question1.php 中的意外 ' 我的网址确实存在 您可能会遇到解析错误,因为您尝试将 JavaScript 作为 php 代码运行。 在哪里指定 Secret_Question2.php 的位置。这是位置->C:\xampp\htdocs\uni-saga\saga_files\saga_step\saga_step3 如果文件 Secret_Question1.php 和 Secret_Question2.php 位于同一目录中,则上述示例将起作用。【参考方案2】:

代替这一行:

header("location:../saga_step3/Secret_Question2.php");

你可以使用javascript打开一个新窗口:

echo "<script type='text/javascript'>
    window.open ('yourpage.html','_self',false)
</script>";

如果两个文件的目录相同,请将 yourpage.html 替换为您的文件名

见参考:http://www.w3schools.com/jsref/met_win_open.asp

【讨论】:

i get and error Parse error: syntax error, unexpected ' window.open('../saga_step3/Secret_Question2.php','_self',false) 对不起,我忘了在php中你不能直接调用脚本,现在我已经根据它编辑了代码。

以上是关于php命令不会将我移动到下一页的主要内容,如果未能解决你的问题,请参考以下文章

单击按钮移动到下一页时出错

移动到下一页时不显示对话框[重复]

我们如何导航到一个网页,抓取数据,移动到下一页,然后再做一次?

如何使用angularjs变量使超链接移动到下一页?

PHP验证链接到下一页

离子标签不会转到下一页