我正在制作一个表单来提交数据,但问题是错误没有回显。如果所有字段都输入正确,则表单成功提交数据,但当没有数据时,不会返回错误输出。我把这个回声语句放在标题下面
这是表格...
<label for="Name"> Names:</label>
<input type="text" name="Name" maxlength="25" size="24" class="input"/>
<label for="Email">Email Address:</label>
<input type="text" name="Email" maxlength="30" size="24" class="input"/>
<label for="Subject">Subject:</label><br/>
<input type="text" name="Subject" maxlength="25" size="25" class="input"/>
<label for="Comments">Comments</label><br/>
<textarea rows="6" cols="50" name="Ujumbe"size="140" class="textarea"></textarea>
<input type="submit" value="Send Mail" name="submit" />
这是验证码...
<?php
if(isset($_POST['submit'])){ $error= array();
if(empty($_POST['Name'])) { $error[]='Your name '; }
else if (!empty ($_POST['Name'])){ $Name=mysql_real_escape_string(htmlentities($_POST['Name'])); }
if(empty($_POST['Email'])) {$error[]='Your email address. '; }
else if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$_POST['Email'])){
$Email = mysql_real_escape_string($_POST['Email']);
}
else {
$error[]='That you entered e-mail address is invalid.';
}
if(empty($_POST['Comments'])){ $error[]='Enter a comment '; }
else if (!empty ($_POST['Comments']))
{
$Comments=mysql_real_escape_string(htmlentities($_POST['Comments']));
}
if(empty($_POST['Subject'])){ $error[]='Enter the subject '; }
else if (!empty ($_POST['Comments'])){ $Subject=mysql_real_escape_string(htmlentities($_POST['Subject'])); }
if (empty ($error)){
header("messages.php?x=3");
}
else{
$error_message ='<br/><br/><span class="error"><br />You did not submit the following required information!<br/><br/>' ;
foreach($error as $key => $values) {
$error_message.= "<br/>$values<br/>";
}
$error_message.="</span> <br/><br/><br/>";
}}
?>