php ajax验证用户名是否存在

php ajax验证用户名是否存在

一只萌萌小番薯
浏览 660回答 3
3回答

潇湘沐

下面是通过ajax发送到php上的局部代码$username=mysql_escape_string($_POST['username']);$password=sha1( mysql_escape_string($_POST['password']));$query_string = "SELECT * FROM `users` WHERE `name`='$username' AND `password`='$password';";$result = mysql_query($query_string);if (mysql_num_rows($result) > 0){//$_SESSION['username']=$username;$data = mysql_fetch_row($result);$_SESSION['company']=$data['4'];header("location: index.php");//die();}else {$tip="用户不存在或密码错误";} 

肥皂起泡泡

123456789$("button").click(function(){  $.get("ajax_login.php",{username:'testname'}, function(result){    if(result){    //判断已经存在        alert('用户名已经存在');    }else{        alert('可以注册');    }  });});  
打开App,查看更多内容
随时随地看视频慕课网APP