0

出于某种原因,每当我尝试运行 PHP 时,它只会说“您忘记输入密码”。关于我缺少什么的任何建议?代码本身似乎没有错误......?我尝试了多种选择,但似乎仍然没有解决此错误。我有一个数据库,它正在适当地连接,它似乎没有拉出 password1 字段。

 <?php
echo mysql_error(); 
// Send NOTHING to the Web browser prior to the session_start() line!
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
require_once ('../../mysql_connect.php'); // Connect to the db.
$errors = array(); // Initialize error array.
// Check for an email address.
if (empty($_POST['email'])) {
    $errors[] = 'You forgot to enter your email address.';
} else {
    $e = mysql_real_escape_string(trim($_POST['email']));
}
// Check for a password.
if (empty($_POST['password1'])) {
    $errors[] = 'You forgot to enter your password.';
} else {
    $password1 = mysql_real_escape_string($_POST['password1']);
}
if (empty($errors)) { // If everything's OK.
    /* Retrieve the user_id and first_name for 
    that email/password combination. */
    $query = "SELECT * FROM `Users` WHERE email='$e' AND  
    password1='$password1','$password2'"; 
    $result = @mysql_query ($query); // Run the query.
    $row = mysql_fetch_array ($result, MYSQL_BOTH);
    if ($row) { // A record was pulled from the database.
        //Set the session data:
        session_start(); 
        $_SESSION['first_name'] = $row[1];
        $_SESSION['last_name'] = $row[2];
        $_SESSION['email'] = $row[3];
        $_SESSION['password1'] = $row[4];
        $_SESSION['password2'] = $row[5];
        $_SESSION['registration_date'] = $row[6]; 

        // Redirect:
        header("Location:loggedin.php");
        exit(); // Quit the script.
    } else { // No record matched the query.
        $errors[] = 'The email address and password entered do not match     
those on file.'; // Public message.
    }
} // End of if (empty($errors)) IF.
mysql_close(); // Close the database connection.
} else { // Form has not been submitted.
$errors = NULL;
} // End of the main Submit conditional.

// Begin the page now.
$page_title = 'Login';
include ('header.php');
if (!empty($errors)) { // Print any error messages.
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
    echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}

// Create the form.
?>
<body bgcolor="#c0c6c6"> 
<h2>Please, login here.</h2>
<form action="login.php" method="post">
<p>Email Address: <input type="text" name="email" size="20" maxlength="40" /> </p>
<p>Password: <input type="password" name="password" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>

<?php
include ('footer.php');
?>
4

1 回答 1

7

您的表单包含name="password",但您的 PHP 正在寻找$_POST['password1']。这些名称必须匹配才能正常工作!

于 2013-04-22T22:30:34.243 回答