这是第一页:Index.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<form name="Index" action="Result.php" method="POST">
Username: <input type="text" name="username" id="username" autocomplete="off"><br><br> 1. I identify my gender as... <br>   
<input type="radio" name="gender" value="male">Male<br>   
<input type="radio" name="gender" value="female">Female<br>   
<input type="radio" name="gender" value="others">Others<br><br>
<INPUT Type="submit" Value="Proceed" Onclick="Index.action='Test2.php'; return true;">
</form>
</body>
</html>
<?php
session_destroy();
?>
这是第二页:Test2.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Test2</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<form action="Result.php" method="POST">
2. What is your age?<br>   
<input type="radio" name="age" value="14years">Under 14 years old<br>   
<input type="radio" name="age" value="15years">15-24 years old<br>   
<input type="radio" name="age" value="25years">25-59 years old<br>   
<input type="radio" name="age" value="60years">60-74 years old<br>   
<input type="radio" name="age" value="75years">Above 75 years old<br><br><br><br>
<INPUT Type="submit" Value="Proceed" Onclick="Index.action='Test3.php'; return true;">
</form>
</body>
</html>
<?php
session_destroy();
?>
这是第三页:Test3.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Test3</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<form action="Result.php" method="POST">
3. Please specify your ethnicity (race)<br>   
<input type="radio" name="race" value="chinese">Chinese<br>   
<input type="radio" name="race" value="malay">Malay<br>   
<input type="radio" name="race" value="indian">Indian<br>   
<input type="radio" name="race" value="others">Others<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
session_destroy();
?>
这是最后一页:Result.php
<?php
session_start();
?>
<html>
<head>
<title>Result</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
Welcome!
<?php echo $_POST["username"]; ?><br>
<?php
$gender = $_POST['gender'];
if ($gender == "others")
echo "<font size='5'>You are not normal</font><br><br>";
else
echo "<font size='5'>You are normal</font><br><br>";
$age = $_POST['age'];
if (($age == "60years") || ($age == "75years"))
echo "<font size='5'>You are old man</font><br><br>";
else
echo "<font size='5'>You are young man</font><br><br>";
$race = $_POST['race'];
if ($race == "others")
echo "<font size='5'>You are from other race</font><br><br>";
else
echo "<font size='5'>You are from one of three races</font><br><br>";
?>
</body>
</html>
<?php
session_destroy();
?>
所以,这是四个页面:Index.php - &gt; Test2.php - &gt; Test3.php - &gt; Result.php其中Result.php显示文本框和单选按钮的值(如果... else)。但是当我运行页面时:Index.php转到Test2.php并跳过Test3.php并直接转到Result.php。在Reslt.php中,我得到了这个结果: enter image description here
那么,我该怎么办?我在互联网上搜索并尝试了不同的解决方案,但无法按预期工作。之后,我发现按钮可能存在一些问题。所以,我再次上网寻找合适的解决方案,但未能这样做。现在我不知道该怎么做。对代码的一些解释对我来说将是一个很大的帮助。谢谢;)
答案 0 :(得分:0)
您应该在每个页面上获得所需的值,并将它们发布到下一页。
例如,在test2.php
,
$username = $_POST["username"];
$gender = $_POST['gender'];
<input type="hidden" name="username" id="username" value="<?php echo $username; ?>">
<input type="hidden" name="gender" id="gender" value="<?php echo $gender; ?>">