<?php //Necromantic delusions if(isset($_POST['username']) && $_POST['username']){ echo 'ni ying gai zai zhe li jin xing shu ju ku de cha xun cao zuo lai pan duan gei chu de yong hu ming "' . $_POST['username'] . '" shi fou cun zai';exit; }?> <script src="jquery.js"></script> <script language="javascript"> function checkUsername(username){ $.post("test.php", {"username": username}, function(data){ alert(data); }); } </script> <input type="text" name="username" onblur="checkUsername(this.value)">
<?php
//Necromantic delusions
if(isset($_POST['username']) && $_POST['username']){
echo 'ni ying gai zai zhe li jin xing shu ju ku de cha xun cao zuo lai pan duan gei chu de yong hu ming "' . $_POST['username'] . '" shi fou cun zai';exit;
}?>
<script src="jquery.js"></script>
<script language="javascript">
function checkUsername(username){
$.post("test.php", {"username": username}, function(data){
alert(data);
});
}
</script>
<input type="text" name="username" onblur="checkUsername(this.value)">
//Necromantic delusions
if(isset($_POST['username']) && $_POST['username']){
mysql_connect('dbhost', 'dbuser', 'dbpasswd') or die('数据库连接失败');
mysql_select_db('your_db_name') or die('数据库不存在');
mysql_query('set names gbk');//或者set names utf8 $sql = 'select * from your_table_name where username = "' . $_POST['username'] . '"';
$res = mysql_query($sql);
if($res){
//用户名存在了
echo 'isset';exit;
}
//用户名还不存在
echo 'unisset';exit;
}?>
<!-- 这里包含jquery,你也可用自己写ajax代码 -->
<script src="jquery.js"></script>
<script language="javascript">
function checkUsername(username){
$.post("test.php", {"username": username}, function(data){
if(data == "isset"){
alert("用户名已经存在");
/*
在这里你还可用增加一些自己的javascript代码来实现一些后续操作,具体就看你的需求了
*/
}else if(data == "unisset"){
alert("恭喜您,用户名可用");
}else{
alert("出现错误:" + data);
}
});
}
</script>
<input type="text" name="username" onblur="checkUsername(this.value)">
if($res){
改成
if(mysql_num_rows($res)){
<li class="t3"></li>
<li class="t1">用户名:</li><li class="t2"><input name="User" type="text" class="text_1" id="User" size="30">
<input name="pod" type="hidden" id="pod" value="0">
</li>
<li id="re_1" class="t3"></li>
<li class="t1">密 码:</li><li class="t2"><input name="Passwd" type="password" class="text_1" id="Passwd" size="30">
</li>
<li id="re_2" class="t3"></li>
<li class="t3">
<input name="Submit3" type="button" class="button_1" value="确认登录" onClick="login();"> <input name="Submit3" type="button" class="button_1" value="免费注册">
</li>
<li class="t3"></li>
</ul>
<?php
header('Content-type: text/html; charset=gb2312');
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
session_start();
unset($_SESSION['USERID']);
unset($_SESSION['USER']);
unset($_SESSION['TIME']);
unset($_SESSION['ATTE']);
//require_once("../Include/config.inc.php");
if($_GET["User"] !=""){
$get_User = $_GET["User"];
}
else{
echo "<script>document.getElementById(\"re_1\").innerHTML = '用户名不能为空'</script>";
echo "<script>document.getElementById(\"User\").focus();</script>";
echo "<script>document.getElementById(\"User\").select();</script>";
exit;
}
?>
你看看这个当不写用户名时,才显示用户名不能为空这段代码怎样才能实现呀
=>
<input name="User" type="text" class="text_1" id="User" size="30" onblur="javascript: if(!this.value)alert('用户名不能为空');">
<script>
function checkForm(form){
if(!form.user.value){
alert("用户名不能为空!");
return false;
}
}
</script><form onsubmit="return checkForm(this)">
用户名:<input type="text" name="user">
<input type="submit">
</form>