有人可以帮我理解为什么我会收到此通知。我尝试按照此处的教程创建表单验证,但我得到了
“注意:未定义的索引:第 53 行 ...\workspace\Registration\registerValidation.php 中的 last_name”
<?php
$errors = array();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//validation
$testlName = $_POST['last_name'];
if(preg_match("([^A-Za-z0-9])", $testlName)){
$errors['last_name'] = "Please enter a valid last name";
}
//more validation code
}
function form_row_class($name){
global $errors;
return $errors[$name] ? "form_error_row" : "";
}
function error_for($name){
global $errors;
if($errors[$name]){ //this is line 53
return "<div class='form_error'>".$errors[$name]. "</div>";
}
}
?>
<form name="form1" method="post" action="registerValidation.php" >
<table class="form">
<tr class="<?php echo form_row_class("last_name") ?>">
<th><label for="last_name">Last Name</label></th>
<td>
<input name="last_name" id="last_name" type="text" size="15" maxlength="20" value="<?php if(isset($testlName)){echo htmlspecialchars($_POST['last_name']);}?>" />
<?php if(isset($testlName)){echo error_for('last_name');}?>
</td>
</tr>
</table>
<p><input type="submit" name="submit" value="register"></p>
任何想法为什么我会收到通知?我是 php 新手,所以解释会很受欢迎,谢谢!
~喵喵