21,886
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<title>登录页面</title>
<meta charset="utf-8">
</head>
<body>
<form method="post" action="doaction.php">
<table>
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value=" 登 录 "></td>
<td>没有账号?<a href="reg.html">立即注册</a></td>
</tr>
</table>
</form>
</body>
</html>
<?php
header("Content-type:text/html;charset=utf-8");
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) || empty($password)){
echo "<script>alert('用户名或密码不能为空!'); history.go(-1);</script>";
}else{
include "conn.php";
$sql = "SELECT username, password FROM user WHERE username='$username' && password='$password'";
$res = $conn->query($sql);
$no = $res->num_rows;
if(!$no){
echo "<script>alert('用户名或密码错误'); history.go(-1);</script>";
}else{
echo "<script>alert('登录成功!'); location.href='index.html';</script>";
}
}