这是第一页: 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 -> Test2.php -> Test3.php -> Result.php,Result.php显示文本框和单选按钮(if...else)的值。但是当我运行页面时: Index.php转到Test2.php,跳过Test3.php并直接转到Result.php。在Reslt.php中,我得到了这样的结果:在这里输入图像描述
那我该怎么办?我在互联网上搜索,尝试了不同的解决方案,但无法像我预期的那样工作。在那之后,我发现按钮可能有一些问题。所以,我再一次上网寻找合适的解决方案,但没有做到这一点。现在我不知道该怎么做了。一些关于代码的解释对我来说将是一个很大的帮助。(谢谢;)
发布于 2018-06-17 04:48:23
您应该在每一页上获得所需的值,并将它们张贴到下一页。
例如,在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; ?>">https://stackoverflow.com/questions/50893692
复制相似问题