3 回答

TA貢獻1804條經驗 獲得超3個贊
我明白了,沒有人注意到我有if ($err == ""),是的,我只有,if ($err = "")但重點是它總是錯誤的,因為我總是有一兩個字段是空的,我在!那里錯過了一個點,一切都會好起來的。哦,是的,我也錯過了name提交輸入的屬性。但是我非常感謝你們!
這是最終的工作代碼
<?php
print_r($_POST);
if(array_key_exists("submit", $_POST)){
$error = "";
if(!($_POST['email']) ){
$error.="You need to type in email";
}
if(!$_POST["password"]){
$error.="You need to type in password";
}
}
?>
<div id="error"><?php echo $error ?></div>
<form method="post" >
<input type="text" placeholder="username" name="email">
<input type="password" placeholder="password" name="password">
<input type="checkbox" name="StayLoggedIn" value="1">
<input type="submit" name="submit" value="Sign Up">
</form>

TA貢獻1818條經驗 獲得超11個贊
你不需要發送“提交”鍵,它實際上是沒用的。讓它工作所需的只是刪除“if”條件:
if(array_key_exists("submit", $_POST)){
因為如果數據存在(電子郵件和密碼),您就可以抓取數據。你也可以像這樣改進你的代碼:
$err = "no error";
if(!$_POST["email"]){
$err = "You need to type in email";
} else if(!$_POST["password"]){
$err = "You need to type in password";
}
最后刪除不必要的“if-else”檢查。
希望能幫助到你
- 3 回答
- 0 關注
- 184 瀏覽
添加回答
舉報