注册页面之前先验证用户名是否存在的php代码
reg.PHP
<div class="codetitle"><a style="CURSOR: pointer" data="21448" class="copybut" id="copybut21448" onclick="doCopy('code21448')"> 代码如下:
<div class="codebody" id="code21448">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<script type="text/javascript" src="js/func.js">
<style type="text/css">
td{
height:30px;
vertical-align:middle;
align:center;
}
#myText{
width:600px;
}
注册页面 <?
PHP error_reporting(0);
//不让
PHP报告有错语发生。如果不
关闭好有类似这的错语 Warning: preg_
match() 关闭就不出现了
session_start();
header("Cache-control: private");
$conn = @
MysqL_connect("localhost","root","")or die("
数据库连接
错误");
MysqL_select_db("bbs",$conn);
MysqL_query("set names utf8");
if($_POST['submit'])
{
$username = $_POST["username"];
$
sql="select userName from user_info where userName='$username'";
// echo $
sql;
$query=
MysqL_query($
sql);
$rows =
MysqL_num_rows($query);
if($rows > 0){
echo "";
}else{
$user_in = "insert into user_info (username,pass,sex,qq,email,img) values ('$_POST[username]',md5('$_POST[pass]'),'$_POST[sex]','$_POST[qq]','$_POST[email]','$_POST[img_select]')";
//echo $user_in;
MysqL_query($user_in);
echo "";
}
//javascript:history.go(-1)
}
?>
<form action="reg.
PHP" name="reg_form" method="post" onsubmit="return check_reg()">
<table name="reg_table" align="left">
<tr>
<td>
用户:</td><td>
</td>
</tr>
<tr>
性别:</td> <td>女<input type="radio" value="1" name="sex"/> 男 保密</td> </tr> <tr> <td>密码:</td><td><input name="pass" class="myText" type="password" onblur="check_len(this)"/><span id="show_pass" style="color:red;"></td> </tr> <tr> <td>重复密码:</td><td><span id="show_repass" style="color:red;"></td> </tr> <tr> <td>QQ:</td><td><input type="text" class="myText" name="qq" onblur="check_qq(this)"/><span style="color:red;" id="show_qq"></td> </tr> <tr> <td>邮箱:</td><td><input type="text" class="myText" name="email" onblur="check_email(this)"/><span id="show_e" style="color:red;"></td> </tr> <tr> <td height="60">头像:</td> <td> <select name="img_select" onchange="img_change(this)"> <img src="/bbs/img/101.gif" id="tx_change" style="width:50px; height:65px;" alt=""/> </td> </tr> <tr height="20" align="justify">
| <input type="submit" value="注册" name="submit" style="margin-right:5px;"/></td> <td><input type="reset" value="重置" name="reset" style="margin-left:5px;"/></td> </tr> <tr> <td colspan="2">我已有账号现在<a href="login.php">登录</td> </tr> </table>
|