phpmyadmin
首先在phpmyadmin新建一个数据库mydb,在此数据库下新建表users。然后在插入里输入以下内容:
现在在浏览界面,就成这样了:
后端
记得打开phpstudy的mysql服务,否则会报错
login.html:登录界面。当用户点击submit就会跳转到login.php进行查询。
<head>
<meta charset="utf-8">
<title>登录页面</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
form {
border: 3px solid #f1f1f1;
}
input[type=text],
input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #04AA6D;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.container {
padding: 16px;
}
</style>
</head>
<body>
<form action="login.php" method="post">
<div class="container"">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required>
<button type="submit">Login</button>
<label> <input type="checkbox" checked="checked" name="remember"> Remember me</label>
</div>
</form>
</body>
</html>
login.php
<?php
session_start();
$_session=array();
session_destroy();
?>
<?php
$username=$_POST['username'];
$password=$_POST['password'];
$conn=mysqli_connect('localhost','root','root','mydb');
$sql="select username,password from users where username='$username' and password='$password'";
$result=mysqli_query($conn,$sql);
$a=mysqli_fetch_array($result);
if($a['username']==$username && $username!=''){
$_session['login']=true;
header('Location:page.html');
}else{echo "登录失败,请重新登录或注册帐号!";}
?>
然后在浏览器访问
用户名输入tom,密码输入123.提示登录成功
标签:数据库,padding,mysql,login,php,border From: https://www.cnblogs.com/y0uth/p/17784022.html