使用数据库表

时间:2017-11-15 19:34:10

标签: php mysql

我是PHP新手并且遵循我的导师给我的代码。但是,当我去检查电子邮件和密码是否与我表中的数据匹配时,它会继续告诉我

  

发生以下错误:
   - 输入的电子邮件地址和密码与文件中的不同。"

另外,我在顶部收到此警告

  

警告:mysqli_fetch_array()要求参数1为mysqli_result,布尔值在第24行的/home/****/public_html/Project/htdocs/Home/customerlogin.php中给出

我在CPanel中的表名为" customer"。我的注册页面工作并将用户添加到正确的表格中 - 但我不允许登录。我已经验证了mysqli_connect.php也正常运行。

任何帮助都表示赞赏 - 就像我说的那样,我对此非常陌生并获得了此代码。

谢谢!

我的customerlogin.php如下:

<?php
// 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 ('../../mysqli_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 = mysqli_real_escape_string($dbc, trim($_POST['email']));
}
// Check for a password.
if (empty($_POST['password'])) {
    $errors[] = 'You forgot to enter your password.';
} else {
    $p = mysqli_real_escape_string($dbc, $_POST['password']);
}
if (empty($errors)) { // If everything's OK.
    /* Retrieve the user_id and first_name for 
    that email/password combination. */
    $query = "SELECT * FROM customer WHERE email='$e' AND pass='$p'"; 
    $result = mysqli_query ($dbc, $query); // Run the query.
    $row = mysqli_fetch_array ($result);
    if ($row) { // A record was pulled from the database.
        //Set the session data:
        session_start(); 


        // Redirect:
        header("Location:../Home/customerloggedin.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.
mysqli_close($dbc); // 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 ('../includes/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.
?>
<h2>Please, login here.</h2>
<form action="customerlogin.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 ('../includes/footer.php');
?>

0 个答案:

没有答案