标签:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 <script src="jquery-1.11.2.min.js"></script> 7 </head> 8 9 <body> 10 <h1>登录界面</h1> 11 <div>用户名:<input type="text" id="uid"/></div> 12 <div>密码:<input type="text" id="pwd"/></div> 13 <div><input type="button" id="btn" value="登录"/></div> 14 <br /> 15 用户名: 16 <input type="text" id="uidz"/> 17 <div style="color:red" id="xs"></div> 18 </body> 19 20 <script type="text/javascript"> 21 $(document).ready(function(e) { 22 23 $("#uidz").blur(function(){ 24 var uid = $(this).val(); 25 $.ajax({ 26 27 url:"chuli.php", 28 data:{uid:uid}, 29 dataType:"TEXT", 30 type:"POST", 31 success: function(data){ 32 if(data=="1") 33 { 34 $("#xs").text("该用户名已经存在!"); 35 } 36 else 37 { 38 $("#xs").text(""); 39 } 40 41 } 42 43 }); 44 45 46 }) 47 48 49 $("#btn").click(function(){ 50 51 var uid = $("#uid").val(); 52 var pwd = $("#pwd").val(); 53 54 55 $.ajax({ 56 57 url:"chuli.php", 58 data:{uid:uid,pwd:pwd}, 59 type:"POST", 60 dataType:"TEXT", 61 success: function(data){ 62 63 if(data == "OK") 64 { 65 window.location = "index.php"; 66 } 67 else 68 { 69 alert(data); 70 } 71 72 } 73 74 }); 75 76 77 }) 78 79 80 }); 81 </script> 82 83 </html>
处理界面
1 <?php 2 include("mydbda.php"); 3 /*$uid = $_POST["uid"]; 4 $pwd = $_POST["pwd"]; 5 //1.造连接对象 6 $db = new mysqli("localhost","root","123","mydb"); 7 8 //2.判断是否连接成功 9 if(mysqli_connect_error()) 10 { 11 echo "连接失败"; 12 13 //退出整个程序 14 exit; 15 } 16 else 17 { 18 $sql = "select count(*) from login where UserName=‘".$uid."‘ and Password=‘".$pwd."‘"; 19 20 $result = $db->query($sql); 21 22 $row = $result->fetch_row(); 23 24 if($row[0]==0) 25 { 26 echo "用户名或密码错误"; 27 } 28 else 29 { 30 echo "OK"; 31 } 32 }*/ 33 34 $uid = $_POST["uid"]; 35 36 $db = new mydbda(); 37 $sql = "select count(*) from login where UserName=‘".$uid."‘"; 38 39 $str = $db->Select($sql,"CX","mydb"); 40 41 echo $str; 42 ?>
1 <?php 2 class mydbda 3 { 4 var $host = "localhost"; 5 var $username = "root"; 6 var $password = "123"; 7 var $database = "mydb"; 8 9 /** 10 功能:执行SQL语句,返回结果 11 参数:$sql:要执行的SQL语句 12 $type:SQL语句的类型,CX代表查询,QT代表其他 13 $data:要操作的数据库 14 返回值:如果是查询,返回结果集 15 如果是其他语句,执行成功返回OK,失败返回NO 16 */ 17 function Select($sql,$type,$data) 18 { 19 20 //1.造连接对象 21 $db = new mysqli($this->host,$this->username,$this->password,$data); 22 23 //2.判断是否连接成功 24 if(mysqli_connect_error()) 25 { 26 echo "连接失败"; 27 28 //退出整个程序 29 exit; 30 } 31 else 32 { 33 //4.执行SQL语句 34 35 $result = $db->query($sql); 36 37 if($type == "CX") 38 { 39 $str = ""; 40 41 while($row = $result->fetch_row()) 42 { 43 for($i=0;$i<count($row);$i++) 44 { 45 $str=$str.$row[$i]."^"; 46 } 47 $str = substr($str,0,strlen($str)-1); 48 $str = $str."|"; 49 50 } 51 $str = substr($str,0,strlen($str)-1); 52 return $str; 53 } 54 else 55 { 56 if($result) 57 { 58 return "OK"; 59 } 60 else 61 { 62 return "NO"; 63 } 64 } 65 66 67 } 68 } 69 70 71 72 } 73 ?>
标签:
原文地址:http://www.cnblogs.com/sihuiming/p/5205113.html