drd94483 2018-06-17 04:29
浏览 102
已采纳

undefined index:XAMPP中的名称

This is the first page: 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> &ensp;&ensp;
    <input type="radio" name="gender" value="male">Male<br> &ensp;&ensp;
    <input type="radio" name="gender" value="female">Female<br> &ensp;&ensp;
    <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();
?>

This is the second page: 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> &ensp;&ensp;
    <input type="radio" name="age" value="14years">Under 14 years old<br> &ensp;&ensp;
    <input type="radio" name="age" value="15years">15-24 years old<br> &ensp;&ensp;
    <input type="radio" name="age" value="25years">25-59 years old<br> &ensp;&ensp;
    <input type="radio" name="age" value="60years">60-74 years old<br> &ensp;&ensp;
    <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();
?>

This is the third page: 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> &ensp;&ensp;
    <input type="radio" name="race" value="chinese">Chinese<br> &ensp;&ensp;
    <input type="radio" name="race" value="malay">Malay<br> &ensp;&ensp;
    <input type="radio" name="race" value="indian">Indian<br> &ensp;&ensp;
    <input type="radio" name="race" value="others">Others<br><br>
    <input type="submit" name="submit" value="Submit">
  </form>
</body>

</html>
<?php
session_destroy();
?>

This is the last page: 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();
?>

So, This is the four pages do: Index.php -> Test2.php -> Test3.php -> Result.php where Result.php displays the values of the textbox and radio buttons (if...else). But when I run the pages: Index.php go to Test2.php and just skip the Test3.php and direct go to Result.php. And in Reslt.php, I got this outcome: enter image description here

So, what should I do? I searched over the Internet and tried different solutions out there but couldn't work as I expected. After that, I discovered that there maybe has some problems with the button. So, again I go to Internet to find proper solution but failed to do so. Now I have no idea how to do that. Some explanations with code will be a big help for me. Thanks ;)

  • 写回答

1条回答 默认 最新

  • douyong5825 2018-06-17 04:48
    关注

    You should get the value you need on every page,and post them to the next page.

    For example,in 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; ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。