我已经完成了其余的代码工作,但看起来我的if语句适用于年龄,不断陷入困境并重新运行声明。我可以在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>
有谁能告诉我我的陈述有什么问题?
答案 0 :(得分:0)
您在if(!is_numeric($age))
分支,但未指定$age
。
分配$age=$_SESSION['age'];
或检查if(!is_numeric($_SESSION['age']))