嘿,我有一些問題沒有讓我的錯誤顯示在我的表單上。這是代碼我現場運行(只是在我的託管網站上測試它),當我把東西放到測試領域時它沒有顯示任何東西。任何想法可能是錯的?註冊表單上的Php「errors」
<?php
if ($_POST['submit']) {
if (!$_POST['email']) $error.="Please enter your email!";
else if !(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="Uh Uh uh, you didn't enter a valid email address!";
if (!$_POST['password']) $error.="Please enter a password!";
else {
if (strlen($_POST['password'])<8) $error.="Please enter a password of at least 8 characters.";
if (!preg_match('`[A-Z]`',$_POST['password'])) $error.="Please include at least one capital letter in your password."
}
if ($error) echo "There were error(s) in your sign up details:".$error;
}
?>
<form method="post">
<input type ="email" name="email" id="email" />
<input type ="password" name="password" />
<input type ="submit" name="submit" value ="Click for Cookies" />
</form>
有很多事情要說,但最重要的是要以合理的方式縮進代碼(如果您對如何編寫格式良好的代碼沒有任何意見,請查看PSR建議)。要知道數組項是否存在,請不要寫'if($ _POST ['thing'])'但使用'isset',例如:if(isset($ _ POST ['thing']))'並在需要後檢查值。 –