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

问题描述:

Iam尝试创建一个页面,其中用户输入秘密问题,然后单击下一个导航到下一个问题。我试图检查我的代码,找不到任何问题。请帮忙! Secret_Question1.phpphp命令不会将我移动到下一页

<?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"); 
    } 
?> 
+0

什么不工作? naviagation到另一个页面?或别的东西 –

+0

是的导航到另一个页面 –

到位这行:

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

+0

我得到和错误 解析错误:语法错误,意外的' window.open('../saga_step3/Secret_Question2.php','_self',false) –

+0

对不起,我忘了提及,在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; 
    ?> 
+0

我仍然得到一个解析错误 - >解析错误:语法错误,意外的'

+0

我的网址确实存在 –

+0

您可能会得到一个解析错误,因为你尝试运行JavaScript作为PHP代码。 – Andreas