drd94483
drd94483
2018-06-17 04:29

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 douyong5825 3年前

    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; ?>">
    
    点赞 评论 复制链接分享

为你推荐