注册页面之前先验证用户名是否存在的php代码
发布时间:2020-05-24 17:39:18 所属栏目:PHP 来源:互联网
导读:注册页面之前先验证用户名是否存在的php代码,需要的朋友可以参考下
|
reg.php <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> |
