第一步
登录界面
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Login</h1>
<form action="phptest/welcome.php" method="get">
<label >用户名:</label><input type="text" name="username"><br>
<label >密码:</label><input type="text" name="password"><br>
<input type="submit" name="submit" value="登录" class="submit">
</form>
</body>
</html>
welcome.php
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<?php
$username = $_GET['username'];
$password = $_GET['password'];
if($username==NULL or $password==NULL)
echo "请输入用户名和密码";
else
{
$link = mysqli_connect('127.0.0.1','root','root123','testsql');
if(!$link){
die("数据库连接没成功QAQ".mysqli_connect_errno());
}
echo "数据库连接成功啦!!<br>";
$sql="select * from testsql.users where name='$username' and password = '$password'";
$result=mysqli_query($link,$sql);
$row = mysqli_fetch_assoc($result);
if($row){
echo "欢迎".$username;
}
else{
echo "但是用户名或者密码不正确,失败了";
}
}
第二部
建库
建表并插入数据
create table users(
id int(11) not null,
name varchar(20) not null,
password varchar(20) not null,
primary key(id)
)
insert into
users(id,name,password)
values (1,'admin','admin123')
到这里就已经完成了。
接下来测试
把html和php放在小皮WWW下
打开网页
先输入错误的,如admin,hahaha
输入正确的admin,admin123
到这里就成功了