61,110
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#content{
margin: auto;
}
</style>
</head>
<body>
<div id="content">
<form name="userForm">
<label for="username"name+pwd>
<input id="uname" type="text" name="username" placeholder="用户名"/>
<span id="tips"></span>
</label>
<br />
<label for="password">
<input id="pwd" type="password" name="password" placeholder="请输入6~16位的密码"/>
</label>
<br />
<input id="submit" type="button" value="登陆"></input>
</form>
</div>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$('#submit').click(function(){
var name = $('#uname').val();
var pwd = $('#pwd').val();
$.post('login.php',{username:name,password:pwd},function(res){
if(res=='成功'){
console.log(res+'success');
$('#tips').text('登陆成功!');
}else{
$('#tips').text('用户名和密码不匹配!');
}
})
}
)
</script>
</body>
</html>
<?php
if(isset($_POST) && !empty($_POST)){
$username = $_POST['username'];
$password = $_POST['password'];
//将用户名密码代入查询语句查询是否存在
include 'mysql_connect.php';
mysqli_select_db($conn, 'db_test');
$sql = "select * from user where (name ='$username') and (password ='$password')";
$check_query = mysqli_query($conn,$sql);
$result = mysqli_fetch_array($check_query);
if($result){
$response = "成功";
}else{
$response = "失败";
}
echo $response ;
}
function check(){
$('#submit').click(function(){
var name = $('#uname').val();
var pwd = $('#pwd').val();
$.post('login.php',{username:name,password:pwd},function(res){
if(res=='成功'){
console.log(res+'success');
$('#tips').text('登陆成功!');
return false;
}else{
$('#tips').text('用户名和密码不匹配!');
return false;
}
})
}
)
}