posts - 4, comments - 2, trackbacks - 0, articles - 0

2008年4月17日

前台(reg.html):
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />

<title>Ajax Example</title>

<script type="text/javascript">

var xmlobj;                                     //定义XMLHttpRequest对象

function CreateXMLHttpRequest()

{

    
if(window.XMLHttpRequest)
{//Mozilla浏览器
    xmlobj=new XMLHttpRequest();
    
if(xmlobj.overrideMimeType)
    
{//设置MIME类别
       xmlobj.overrideMimeType("text/xml");
    }

}

else if(window.ActiveXObject)
{//IE浏览器
   try
   
{
    xmlobj
=new ActiveXObject("Msxml2.XMLHttp");
   }

   
catch(e)
   
{
    
try
    
{
     xmlobj
=new ActiveXobject("Microsoft.XMLHttp");
    }

    
catch(e)
    
{
    }

   }

}


}


function Validate()                             //主程序函数

{

    CreateXMLHttpRequest();                     
//创建对象

    
var showurl = "show.php?username=" + document.getElementById ("username").value;                                    //构造URL

    xmlobj.open(
"GET", showurl, true);          //调用validate.php

    xmlobj.onreadystatechange 
= StatHandler;    //判断URL调用的状态值并处理

    xmlobj.send(
null);                          //设置为不发送给服务器任何数据

}


function StatHandler()                          //用于处理状态的函数

{

    
if(xmlobj.readyState == 4 && xmlobj.status == 200)                                                                      //如果URL成功访问,则输出网页

    
{
document.getElementById(
"msg").innerHTML=xmlobj.responseText ;
    }


}


</script>

</head>

<body>

<p><form action="#">

用户名:
<input type="text" id="username" onBlur="Validate();" onChange="Validate();">

<input type="button" value="用户名验证" onClick="Validate();">

<div id="msg"></div>

</form></p>

</body>

</html>

后台(show.php):
<?php

$conn = mysql_connect("localhost", "root", "123456");

$user = $_GET["username"];

$querySQL = "SELECT * FROM users WHERE name = '".$user."'";

mysql_select_db("users", $conn);

$rs = mysql_query($querySQL, $conn);

$rs_cnt = mysql_num_rows($rs);

if($rs_cnt==1)
{
echo "<font color=RED>该用户名已被人使用</font>";
}
else if($rs_cnt==0)
   {
    
echo "<font color=GREEN>该用户名未被人使用</font>";
   }
   
else
    
echo "<font color=RED>用户名验证程序出错</font>";
?>

posted @ 2008-04-17 22:09 LiveStar 阅读(3743) | 评论 (1)编辑 收藏

2008年3月31日

以下方法仅供参考,只是介绍下这一种方法而已。欢迎指正!!

前台(image.html):
 1<html>
 2<head>
 3<title>上传图片</title>
 4</head>
 5<body>
 6<form method="post" action="upimage.php" enctype="multipart/form-data"><center><br><br><br><br>
 7  <input type="hidden" value="204800" name="MAX_FILE_SIZE"/>
 8  File: <input type="file" name="imgfile" /><br><br>
 9  <input type="submit" value="OK" name="submitbtn" style="width:100px;height:23px"/></center>
10 </form>
11</body>
12</html>

后台处理(upimage.php):
 1<?php 
 2    //向数据库中插入图片
 3    $imgfile=$_FILES['imgfile'];
 4    $submitbtn=$_POST['submitbtn'];
 5    if($submitbtn=='OK' and is_array($imgfile))
 6    {
 7        $name=$imgfile['name'];  //取得图片名称
 8        $type=$imgfile['type']; //取得图片类型
 9        $size=$imgfile['size'];  //取得图片长度
10        $tmpfile=$imgfile['tmp_name'];  //图片上传上来到临时文件的路径
11        if($tmpfile and is_uploaded_file($tmpfile))  //判断上传文件是否为空,文件是不是上传的文件
12        {
13            //读取图片流
14            $file=fopen($tmpfile,"rb");
15            $imgdata=bin2hex(fread($file,$size));  //bin2hex()将二进制数据转换成十六进制表示
16            fclose($file);
17            
18            $mysqli=mysql_connect("localhost","root","123456");  //连接数据库函数
19            mysql_select_db("test");  //选择数据库
20            //插入出数据库语句,图片数据前要加上0x,用于表示16进制数
21            if(mysql_query("insert into images(name,type,image) values('".$name."','".$type."',0x".$imgdata.")"))
22                echo "<center>插入成功!<br><br><a href='disimage.php'>显示图片</a></center>";
23            else
24                echo "<center>插入失败!</center>";
25            mysql_close();
26        }
27        else 
28            echo "<center>请先选择图片!<br><br><a href='image.html'>点此返回</a></center>";
29    }    
30    else 
31        echo "<center>请先选择图片!<br><br><a href='image.html'>点此返回</a></center>";
32?>

显示图片(disimage.php):
 1<?php
 2    mysql_connect("localhost","root","123456");
 3    mysql_select_db("test");
 4    //显示最新插入的那张图片
 5    $result=mysql_query("select image from images where id=(select max(id) from images)");  
 6    $row=mysql_fetch_object($result);
 7    header("Content-Type:image/pjpeg");  
 8    echo $row->image;
 9    mysql_close();
10?>

posted @ 2008-03-31 20:58 LiveStar 阅读(6015) | 评论 (1)编辑 收藏

2008年3月30日


在查询前插入:mysql_query("set names 'utf8'");

for example:

 1    mysql_connect("localhost","root","123456");
 2    mysql_select_db("test");
 3    mysql_query("set names 'utf8'");
 4    $result=mysql_query("select * from info");
 5    echo "<table border=1>";
 6    echo "<tr><td>name</td><td>id</td><td>tel</td></tr>";
 7    while ($arr=mysql_fetch_array($result))
 8    {
 9        echo "<tr><td>".$arr[0]."</td>";
10        echo "<td>".$arr[1]."</td>";
11        echo "<td>".$arr[2]."</td></tr>";        
12    }
13    echo "</table>";
14    mysql_close();

posted @ 2008-03-30 21:11 LiveStar 阅读(502) | 评论 (0)编辑 收藏

2008年1月17日


                       恭喜下下,today  注册成功 !!

posted @ 2008-01-17 14:29 LiveStar 阅读(441) | 评论 (0)编辑 收藏