web前端全系列 教程
1839个小节阅读:2243.5k
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
$username = $_POST["username"];
$password = $_POST["password"];
$con = mysqli_connect("localhost","root","","itbaizhan");
if($con){
mysqli_query($con,"set names utf8");
$sql = "select * from user where username='$username' and password='$password'";
$result = mysqli_query($con,$sql);
$data = mysqli_fetch_all($result,MYSQLI_ASSOC);
mysqli_close($con);
if($data){
echo json_encode(array(
"user"=>$data,
"msg"=>true
));
}else{
echo json_encode(array(
"msg"=>false,
"user"=>"暂无数据"
));
}
}else{
echo "连接数据库失败";
}
xxxxxxxxxx
<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>
<script src="./jquery-3.6.0.js"></script>
<style>
.container{
width: 400px;
margin: 0 auto;
margin-top: 200px;
}
</style>
</head>
<body>
<div class="container">
<form>
<div>
<label for="username">用户名:</label>
<input type="text" id="username" placeholder="用户名">
</div>
<div>
<label for="password">密码:</label>
<input type="password" id="password" placeholder="密码">
</div>
<input type="submit" id="btn">
</form>
</div>
<script>
$("#btn").click(function(e){
e.preventDefault();
var username = $("#username").val();
var password = $("#password").val();
$.ajax({
type:"post",
url:"../server/login.php",
data:{
username:username,
password:password
},
success:function(data){
console.log(JSON.parse(data));
}
})
})
</script>
</body>
</html>