ajax+php验证用户名重复代码实例
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.phprm.com/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>ajax+php验证用户名重复代码实例</title>
代码如下 | 复制代码 |
<script language="网页特效"> function getrenews(value){//主调函数 function getreadystatehandler(xmlhttp){//服务器返回后处理函数 </script> |
</head>
<body>
代码如下 | 复制代码 |
<table width="75%" border="0"> <tr> <td width="12%">输入用户名</td> <td width="36%"> <input type="text" name="username" id="username" onblur="getrenews(this.value);" /> </td> <td width="52%" id="checkid"> </td> </tr> </table> |
</body>
</html>
把下面代码保存忝13.php
代码如下 | 复制代码 |
<? checkusername(); function checkusername() { $title = trim($_get['title']); if( empty( $title ) ) { return false; } else { mysql教程_connect('localhost','root','root'); mysql_select_db('test'); mysql_query("set names 'gb2312'"); $sql = "select * from cn_user where username ='$title'"; $row = mysql_query($sql); if( mysql_num_rows( $row ) ) { echo 1; } else { return null; } } } |
/*
create table `test`.`cn_user` (
`id` int not null auto_increment ,
`username` varchar( 20 ) not null ,
`times` date null ,
primary key ( `id` )
) engine = myisam
插入数据
insert into `test`.`cn_user` (
`id` ,
`username` ,
`times`
)
values (
null , 'jimmy', null
), (
null , 'www.phprm.com', null
);
*/
?>
本文地址:http://www.phprm.com/database/34411.html
转载随意,但请附上文章地址:-)