函数T_CONTINUE无法运行,并给出未定义索引的错误:第82行上的city1以及city 2和city3。其余if语句确实可以验证用户输入。如果用户忘记输入表格的一部分,则首先显示单个错误消息,然后显示一般errMessage,但不显示。
用户输入所有正确的信息并继续== true之后,它应该回发他们在表单中选择的内容。
<HTML>
<head>
<h1>Weather Wizards Registration Verification Form</h1>
<hr>
<br>
<?php //start PHP codeing
$name=
$parentName=
$email=
$phone=
$member=
$city1="";
$city2="";
$city3="";
$nameErr="";
$parentNameErr="";
$parentEmailErr="";
$parentPhoneErr="";
$memberErr="";
$errMessage ="";
$continue=true;
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$name = test_input($_POST["name"]);
$parentName = test_input($_POST["parentName"]);
$email = test_input($_POST["email"]);
$phone = test_input($_POST["phone"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") { //Name
if (empty($_POST["name"])) {
$nameErr = "You forgot to enter your name.";
$continue==false;
echo $nameErr;
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["parentName"])) { //Parent Name
$parentNameErr = "You forgot to enter your parent or guardian’s name";
echo $parentNameErr;
$continue==false;
}else {
$parentNameErr = test_input($_POST["parentName"]);
}
if (empty($_POST["email"])) { //Email
$parentEmailErr = "You forgot to enter your parent or guardian’s email.";
echo $parentEmailErr;
$continue==false;
}else {
$parentEmailErr = test_input($_POST["email"]);
}
if (empty($_POST["phone"])) { //phone number
$parentPhoneErr = "You forgot to enter your parent or guardian’s phone";
echo $parentPhoneErr;
$continue==false;
}else {
$parentNameErr = test_input($_POST["phone"]);
}
if (empty($_POST["member"])) { //membership
$memberErr = "You forgot to enter your membership status.";
echo $memberErr;
$continue==false;
}else {
$memberErr = test_input($_POST["member"]);
}
}
T_CONTINUE();
// if ($continue) { T_CONTINUE(); }
function T_CONTINUE(){
if($continue = false){
$errMessage = "We need your name and your parent or guradians name,email,phone and your membership status to send information about our workshop. Hit the back button on the browser to try again";
echo $errMessage;
}else if ($continue =true){
if( $_POST["city1"]){
// if Charleston is selected:
echo"You are nearest to our Charleston SC location, the Holy City! Go River Dogs!";
}else if( $_POST["city2"]){
// if per Summerville is selected:
echo"You are nearest to our Summerville SC location, the Birthplace of Sweet Tea! Refreshing!";
}else if( $_POST["city3"]){
// if per Mt. Pleasant is selected:
echo"You are nearest to our Mt. Pleasant, SC location that has a historical and beachy vibe!";
}
}
}
?>
</body>
<style type="text/css">
html{
background-color: lightgray;
}
</style>
</HTML>
答案 0 :(得分:2)
所以您的财产有几个问题。
T_CONTINUE
函数中,您将false
分配给$continue
。您正在做分配而不是比较。 =
与==
$continue
,您需要使用$GLOBALS['continue']
之类的全局数组。ALL
的错误报告。使调试更加容易。在这种情况下不会有太大帮助,因为您正在这种情况下进行作业,并且从技术上讲这不是违法的。