<?php
//设置帐号密码
// $conn = new mysqli('localhost', 'root', 'root', 'qiye');
// $s = "insert into admin(uname,pasd) values('admin','" . md5(123456) . "');";
// $dd = $conn->query($s);
if ($_POST) {
// 接受提交过来的数据
$uname = trim($_POST['uname']);
$pasd = md5($_POST['pasd']);
// 查询数据库
$conn = new mysqli('localhost', 'root', 'root', 'qiye');
$sql = "select * from admin where uname = '$uname' and pasd = '$pasd' ";
$res = $conn->query($sql);
if ($conn->error) {
die($conn->error);
}
$info = $res->fetch_assoc();
// 判断数据
if ($res->num_rows > 0) {
setcookie('admin', $info['id']);
header('Location:index.php');
} else {
$msg = '账号或者密码错误';
}
$conn->close();
}
?>
<?php
// if(!isset($_COOKIE['admin'])){
// header('Location:login.php');
// }
?>