一体化代码,ajax注册认证客户名是还是不是存在

作者: 计算机网络  发布:2019-09-26

html代码

conn.php文件

 代码如下

 代码如下

<script src="ajax.js"></script>
<form>
<table>
<tr>
  <td>用户名:</td>
  <td><input type="text" id="txt1" onKeyUp="showHint(this.value)"></td>
 </tr>
 <tr align="center">
  <td colspan="2"><span id="txtHint"></span></td>
 </tr>
</table>
</form>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script >
var xmlhttp
function showhint(str)
{
if (str.length==0)
  {
  document.getelementbyid("txthint").innerhtml=""
  return
  }
xmlhttp=getxmlhttpobject()
if (xmlhttp==null)
  {
  alert ("browser does not support http request")
  return
  }
xmlhttp.onreadystatechange=statechanged

js文件代码

var geturl="conn.php?q="+str
//sid是增添一个即兴数 幸免页面启用缓存本领·
geturl=geturl+"&sid="+math.random()
geturl=encodeuri(geturl);
geturl=encodeuri(geturl);
xmlhttp.open("get",geturl,true)
xmlhttp.send(null)
}
function statechanged()
{
if (xmlhttp.readystate==4 || xmlhttp.readystate=="complete")
 {
 document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext
 }
}
function getxmlhttpobject()
{
var xmlhttp=null;
try
 {
 // firefox, opera 8.0+, safari
 xmlhttp=new xmlhttprequest();
 }
catch (e)
 {
 // internet explorer
 try
  {
  xmlhttp=new activexobject("msxml2.xmlhttp");
  }
 catch (e)
  {
  xmlhttp=new activexobject("microsoft.xmlhttp");
  }
 }
return xmlhttp;
}

 代码如下

</script>
</head>
<body bgcolor="#999999">
<center>
<form>
<table>
 <tr>
  <td>用户名:</td>
  <td><input type="text" id="txt1" onkeyup="showhint(this.value)"></td>
 </tr>
 <tr align="center">
  <td colspan="2"><span id="txthint"></span></td>
 </tr>
</table>
</form>
</center>
</body>
</html>

var xmlHttp
function showHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML=""
  return
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  }
xmlHttp.onreadystatechange=stateChanged

 

var geturl="conn.php?q="+str
//sid是充实八个随便数 制止页面启用缓存技艺·
geturl=geturl+"&sid="+Math.random()
geturl=encodeURI(geturl);
geturl=encodeURI(geturl);
xmlHttp.open("GET",geturl,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText
 }
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

 代码如下

php操作

<?php
$q=$_get["q"];
$q = urldecode($q);

 代码如下

if (strlen($q) > 0)
{
  $conn = @mysql教程_connect("localhost","root","1010") or die ("mysql连接错误");
  mysql_select_db("xin",$conn);
  mysql_query("set names 'utf8'");
  
  $sql = "select username from message where username = '$q'";
  $query = mysql_query($sql);
  @$row = mysql_fetch_array($query);
  
  if(!empty($row['username']))
  {
   $response = "<font color=red>已经被注册!</font>";
  }else
  {
   $response = "<font color=blue>恭喜!能够挂号!</font>";
  }
  
  echo $response;
}

<?php
$q=$_GET["q"];
$q = urldecode($q);

?>

if (strlen($q) > 0)
{
  $conn = @mysql_connect("localhost","root","1010") or die ("MySql连接错误");
  mysql_select_db("xin",$conn);
  mysql_query("set names 'utf8'");
  
  $sql = "SELECT username FROM message WHERE username = '$q'";
  $query = mysql_query($sql);
  @$row = mysql_fetch_array($query);
  
  if(!empty($row['username']))
  {
   $response = "<font color=red>已经被登记!</font>";
  }else
  {
   $response = "<font color=blue>恭喜!能够注册!</font>";
  }
  
  echo $response;
}

数据库
drop database if exists `xin`;
create database `xin` /*!40100 default character set utf8 */;
use `xin`;

?>

create table `message` (
  `id` int(11) not null auto_increment,
  `username` varchar(20) default null,
  primary key  (`id`)
) engine=innodb auto_increment=2 default charset=utf8 

终极再交付数据库

 代码如下

DROP DATABASE IF EXISTS `xin`;
CREATE DATABASE `xin` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `xin`;

CREATE TABLE `message` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(20) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

本文由金沙澳门官网送注册58发布于计算机网络,转载请注明出处:一体化代码,ajax注册认证客户名是还是不是存在

关键词:

上一篇:没有了
下一篇:_autoload自动加载类与机制解析