這是我的錯誤功能代碼錯誤消息內嵌輸入
function output_errors($errors) {
return '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>';
}
這是登錄我的PHP代碼
include 'core/init.php';
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) === true || empty($password) === true) {
$errors[] = 'Enter a valid username or password.';
}
elseif (user_exists($username) === false) {
$errors[] = 'User does not exist.';
}
elseif (user_active($username) === false) {
$errors[] = 'Please activate your account first.';
}
else {
if (strlen($password) > 32) {
$errors[] = 'Password too long. <br>';
}
$login = login($username, $password);
if ($login === false) {
$errors[] = 'Incorrect username or password.';
}
else {
$_SESSION['user_id'] = $login; //login returns user_id
header('Location: hashtagphotowall.php');
exit();
}
}
//visual representation of error arrays
//print_r($errors);
}
else {
$errors[] = 'No data received!';
}
if (empty($errors) === false) {
echo output_errors($errors);
}
這是我的HTML登錄表單的代碼
<div id="firstModal" class="reveal-modal" data-reveal aria-hidden="true" role="dialog">
<p class="modal-row"><em>Sign In.</em><hr></p>
<a href="#" class="button small">Connect with Facebook</a>
<p class="hr-enclosed">or login with email</p>
<form action="login.php" method="post">
<div class="field-box">
<input type="text" name="username" placeholder="Username:" />
<input type="password" name="password" placeholder="Password:" />
<input type="submit" name="loginbutton" class="button small" value="LOGIN" />
</div>
</form>
<p class="modal-row-sub">forgot your password? get help <a href="#">here</a>.<br>new user? sign up <a href="#" data-reveal-id="secondModal">here</a>.</p>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
的代碼起作用但錯誤消息上的另一個網頁上顯示。我試着聲明一個沒有值的變量,並用輸入標籤內聯回顯它,但我沒有輸出。也許是因爲我錯誤地使用了錯誤數組。任何幫助,我怎樣才能使錯誤數組嵌入在登錄表單輸入標籤? 謝謝
支架是否正確平衡? if(empty($ _ POST)=== false){'...'else {error} [] ='沒有收到數據!'; }這是正確的邏輯嗎?不應該有選擇..如果沒有錯誤轉到新頁面,如果錯誤,重新顯示錶格並告訴用戶需要修復什麼... – zipzit
是的,它是平衡的。代碼正在工作。我剛添加了'沒有收到數據'。這裏的問題是我不知道如何顯示與html輸入標籤內嵌的錯誤信息。 – monsteruniversity0908
您的* html表單*和*登錄腳本*在同一頁上? –