[英]Survey stuck in a loop
I've got the rest of the code working, but it seems like my if statement for age, keeps getting stuck and reruns the statement. 我已经完成了其余代码的工作,但似乎我的if语句存在年龄问题,一直卡住并重新运行该语句。 I can see in the var_dump that it got the correct value, but it keeps going back to the statement where it says to enter a numeric value. 我可以在var_dump中看到它具有正确的值,但是它会一直返回到说输入数字值的语句。
<?php
session_start();
var_dump($_SESSION);
$isValid = true;
$fullName = "";
$age = "";
$gender = "";
if (isset($_POST) && !empty($_POST))
{
if (isset($_POST['fullName']) && !empty($_POST['fullName']))
{
$_SESSION['fullName'] = $_POST['fullName'];
}
else
{
$isValid = false;
echo "Please fill in your Full Name.";
}
if (isset ($_POST['age']) && !empty($_POST['age']))
{
$_SESSION['age'] = $_POST['age'];
if (empty($_POST['age']))
{
$isValid = false;
echo "Please fill in your Age.";
}
else if(!is_numeric($age))
{
$isValid = false;
echo "Must be a numeric value.";
}
}
else
{
$isValid = true;
}
if (isset($_POST['yourGender']) && !empty($_POST['yourGender']))
{
$_SESSION['yourGender'] = $_POST['yourGender'];
}
else
{
$isValid = false;
echo"Please pick your gender";
}
if ($isValid)
{
header('Location: qp2.php');
}
}
?>
<html>
<head>
<title> Questions Page 1</title>
</head>
<body>
<form method="post" action="qp1.php">
<!--Name -->
Full Name: <input type="text" name="fullName" value="<?php echo $fullName; ?>"/><br/>
<!-- Email -->
Age: <input type="text" name="age" value="<?php echo $age; ?>"/><br/>
<br/>
<!-- How? Dropdown -->
How did you hear about us?
<select name="yourGender" value="<?php echo $gender; ?>">
<option value=""></option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
<br/>
<!-- Submit button -->
<input type="button" value="Back" onclick="location.href='index.php'"/>
<input type="submit" value="Next"/>
</form>
</body>
</html>
Can anyone tell me what is wrong with my statements? 谁能告诉我我的陈述出了什么问题?
You branch on if(!is_numeric($age))
without having assigned $age
. 您在if(!is_numeric($age))
上分支但未分配$age
。
Either assign $age=$_SESSION['age'];
要么分配$age=$_SESSION['age'];
or check if(!is_numeric($_SESSION['age']))
或检查if(!is_numeric($_SESSION['age']))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.