php-ajax案例1

来源:互联网 发布:刷机软件下载 编辑:程序博客网 时间:2024/05/30 04:26

验证页面:



<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title</title>
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>

</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
  <form action="link" method="post" >
      用户名:
  <input type="text" name="tmpname" size="40" maxlength="40" onblur="checkUser(this.value)"/>
  <div id="frankid"></div>
  </form>

</body>
</html>
处理php文件:

<?php
/*
 * Created on 2011-2-26
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

 if($_GET[name]){
    $conn = mysql_connect("localhost","root","123456") or die(mysql_error());
    mysql_select_db("think_frank",$conn) or die("数据库连接失败");
    mysql_query("set names utf8");

    $sql = "SELECT * FROM `think_blog` where title='$_GET[name]'";

    $query = mysql_query($sql,$conn);

    if(is_array(mysql_fetch_array($query))){
        echo "<font color=red>用户名已经存在</font>";
    }else{
        echo "<font color=green>可以使用</font>";
    }

 }
?>
ajax代码看ajax原理理解笔记中来编写。