第104、105讲 雇员管理系统②③-model1模式简单登陆+数据库登陆

版权声明:本文为博主原创文章,未经博主允许不得转载,如需强制转载,请注明出处且需对文章进行评论声明转载。 https://blog.csdn.net/u014449096/article/details/81541596

login.php

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>管理员登陆</title>
</head>
<h1>管理员登陆</h1>
<body>
    <form method="post" action="LoginProcess.php">
        <table border='1px' width='400px'>
            <tr>
                <td>用户登陆</td>
            </tr>
        </table>
        <br /> 用户名:<input type="text" name='username' /><br /> 密 码:<input
            type="password" name='password' /><br /> 是否要保存cookies<input
            type="checkbox" name="iscookies" /><br /> <input type="submit"
            value='提交' />
    </form>
</body>
</html>

LoginProcess.php

<?php
header("content-type:text/html;charset=utf-8");
include 'Constant.php';
$username = $_POST['username'];
$password = $_POST['password'];
echo "<br/>";
echo "username    " . $username;
echo "<br/>";
echo "password    " . $password;
echo "<br/>";
$mysqli = new mysqli(localhost, hostname, password, dbname);
if ($mysqli->connect_error) {
    echo "数据库连接出错" . $mysqli->connect_error;
    exit();
}
$sql = "select password from admin where name='" . $username . "'";
$res = $mysqli->query($sql);
echo "<pre>";
var_dump($res);
echo "</pre>";
$rows = $res->num_rows;
echo "rows = " . $rows;
if ($rows > 0) {
    for ($i = 0; $i < $rows; $i ++) {
        $result = $res->fetch_assoc();
        echo "密码 " . $result["password"];
        if ($result["password"] == md5($password)) {
            echo "可以登陆";
            header("Location:Main.php?name='admin'");
            exit();
        } else {
            echo "不可以登陆";
            exit();
        }
    }
}else {
    echo "当前用户不存在,请注册";
}

猜你喜欢

转载自blog.csdn.net/u014449096/article/details/81541596