我是PHP新手,並且遇到了我的登錄腳本問題,我花了幾個小時的時間查看並找不到我要出錯的地方。PHP登錄表單失敗
每當我嘗試登錄時,我都會按照下面的代碼與「輸入的電子郵件地址和密碼與文件中的電子郵件地址和密碼不匹配,或者您尚未激活您的帳戶」聲明相迎。電子郵件地址和密碼存儲在數據庫中,並使用我的註冊和激活腳本輸入,這兩個腳本都正常工作,並且還通過MySQL連接腳本連接到我的數據庫,並使用配置腳本。
我實際上已經建立了這個腳本基於我一直在採取哪一個現在有點關注的課程!
如果有人對我出錯的地方有什麼建議,我會非常感激。
非常感謝提前!
<?php # login.php
include ('./includes1/headerregistration.html');
require_once ('./includes1/config.php');
$page_title = 'Login';
if (isset($_POST['submitted'])) { // Check if the form has been submitted.
require_once ('./mysql_connect.php');
// Validate the email address.
if (!empty($_POST['email'])) {
$e = escape_data($_POST ['email']);
}
else {
echo '<p><font color="red"size="+1"> You forgot to enter your email address!
</font></p>';
$e = FALSE;
}
// Validate the password.
if (!empty($_POST['pass'])) {
$p = escape_data($_POST ['pass']);
}
else {
$p = FALSE;
echo '<p><font color="red"size="+1"> You forgot to enter your password!
</font></p>';
}
if ($e && $p) { // If everything's OK.
// Query the database.
$query = "SELECT id, first_name FROM Jobseekers WHERE (email='$e' AND pass=SHA('$p')) AND active IS NULL";
$result = mysql_query ($query) or trigger_error("Query: $query\n <br />MySQL Error: " . mysql_error());
if (@mysql_num_rows ($result) == 1) { // A match was made.
// Register the values & redirect.
$row = mysql_fetch_array ($result,MYSQL_NUM);
mysql_free_result($result);
mysql_close();
$_SESSION['first_name'] = $row[1];
$_SESSION['id'] = $row[0];
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR(substr($url, -1) == '\\')) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/indexregtest.php';
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
}
else { // No match was made.
echo '<p><font color="red"size="+1">Either the email address and password entered do not match those on file or you have not yet activated your account.</font></p>';
}
}
else {
echo '<p><font color="red"size="+1">Please try again.</font></p>';
}
mysql_close();
} // End of SUBMIT conditional.
?>
<h1>Login</h1>
<p>Your browser must allow cookies in order to log in.</p>
<form action="login.php"method="post">
<fieldset>
<p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</fieldset>
</form>
<?php
include ('./includes1/footerregistration.html');
?>
html'font'標記和'mysql_ *'庫已被棄用。您是否在註冊時加密數據?如果這樣比較檢查時的加密值。 – julienhaversano
@OP你確定你的數據庫是okey嗎?您可能有重複的條目 – Sanoob
'AND AND IS NULL'。你的意思是'AND AND IS NOT NULL'? – Sasha