'未找到电子邮件地址和密码' PHP& MySQL的

时间:2016-11-19 17:07:12

标签: php mysql

我在登录使用PHP和MySQL创建的网站时遇到问题。注册后,您可以选择进入登录页面,但在尝试使用正确的详细信息登录后,未找到电子邮件地址和密码'显示在显示错误的登录页面上方。

我已经尝试了与此问题相关的堆栈溢出的各种其他论坛,但我没有成功。

以下是3页的代码:

的login.php:

<?php

$page_title='Login';
include('C:\Abyss Web Server\htdocs\header.html');

if(isset($errors)&& !empty($errors))
{
    echo '<p id="err_msg">Oops! There was a problem:<br>';
    foreach($errors as $msg)

    {
        echo "-$msg<br>";

    }
            echo 'Please try again or <a href="register.php">Register</a></p>';
        }

?>

<h1>Login</h1>

<form action="login_action.php"method="POST">
<p>

Email Address: <input type="text" name="email">
</p><p>

Password: <input type="password" name="pass">
</p><p>

<input type ="submit" value = "Login">
</p>

</form>

<?php include ('C:\Abyss Web Server\htdocs\footer.html'); ?>

login_tools.php:

<?php

function load($page='C:\Abyss Web Server\htdocs\login.php')

{

$url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);

$url=rtrim($url,'/\\');
$url.='/'.$page;    

header("Location:$url");
exit();

}

function validate($dbc, $email = '', $pwd = '')


{
    $errors = array();
    if(empty($email))
        {$errors[]=' Enter your email address.';}
    else

    {$e = mysqli_real_escape_string($dbc, trim($email));}


    if(empty($pwd))
        {$errors[]=' Enter your password.';}
    else

        {$p = mysqli_real_escape_string($dbc, trim($pwd));}


    if(empty($errors))
        {
        $q = "SELECT user_id, first_name, last_name FROM users WHERE email = '$e' 
        AND pass =SHA1('$p')";

    $r = mysqli_query($dbc, $q);

    if(mysqli_num_rows($r) == 1)
        {

        $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
        return array(true, $row);

        }
    else
        {$errors[] = ' Email address and password not found.';}

        }

return array(false, $errors);

}

?>


login_action.php:

MySQL数据库名为&#39; site_db&#39;使用表&#39;用户&#39;。

0 个答案:

没有答案