注冊頁面之前先驗(yàn)證用戶名是否存在的php代碼
更新時(shí)間:2012年07月14日 10:33:44 作者:
注冊頁面之前先驗(yàn)證用戶名是否存在的php代碼,需要的朋友可以參考下
reg.php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link rel="stylesheet" type="text/css" href="css/int.css" />
<script type="text/javascript" src="js/func.js"></script>
<style type="text/css">
td{
height:30px;
vertical-align:middle;
align:center;
}
#myText{
width:600px;
}
</style>
<title>注冊頁面</title>
</head>
<body >
<?php
error_reporting(0);
//不讓PHP報(bào)告有錯(cuò)語發(fā)生。如果不關(guān)閉好有類似這的錯(cuò)語 Warning: preg_match() 關(guān)閉就不出現(xiàn)了
session_start();
header("Cache-control: private");
$conn = @ mysql_connect("localhost","root","")or die("數(shù)據(jù)庫連接錯(cuò)誤");
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 "<script type='text/javascript'>alert('用戶名已存在');location='javascript:history.back()';</script>";
}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 "<script type='text/javascript'>alert('寫入成功??!');location.href='login.php';</script>";
}
//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><input id="username" name="username" class="myText" type="text" maxlength="12" /></td>
</tr>
<tr> <!--性別:0 保密 1 女 2 男-->
<td > 性別:</td>
<td>女<input type="radio" value="1" name="sex"/>
男<input type="radio" value="2" name="sex" />
保密<input type="radio" value="0" name="sex" checked/></td>
</tr>
<tr>
<td>密碼:</td><td><input name="pass" class="myText" type="password" onblur="check_len(this)"/><span id="show_pass" style="color:red;"></span></td>
</tr>
<tr>
<td>重復(fù)密碼:</td><td><input name="repass" class="myText" type="password" onblur="check_pass(this)" /><span id="show_repass" style="color:red;"></span></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"></span></td>
</tr>
<tr>
<td>郵箱:</td><td><input type="text" class="myText" name="email" onblur="check_email(this)"/><span id="show_e" style="color:red;"></span></td>
</tr>
<tr>
<td height="60">頭像:</td>
<td>
<select name="img_select" onchange="img_change(this)">
<option value="101" >女 001</option>
<option value="102" >女 002</option>
<option value="103" >女 003</option>
<option value="104" >女 004</option>
<option value="105" >男 001</option>
<option value="106" >男 002</option>
<option value="107" >男 003</option>
<option value="108" >男 004</option>
</select>
<img src="/bbs/img/101.gif" id="tx_change" style="width:50px; height:65px;" alt=""/>
</td>
</tr>
<tr height="20" align="justify">
<td align="right" ><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">我已有賬號(hào)現(xiàn)在<a href="login.php">登錄</a></td>
</tr>
</table>
</form>
</body>
</html>
func.js
//根據(jù)下拉框變換圖片
function img_change(thisObj){
var imgsrc = "/bbs/img/"+ thisObj.value+".gif";
document.getElementById("tx_change").src=imgsrc;
}
//檢查是否都符合 注冊 要求
function check_reg()
{
if(check_len() && check_pass() && check_email() && check_qq())
{
return true;
}else{
return false;
}
}
//檢查密碼長度不能少于6
function check_len(thisObj){
if(thisObj.value.length==0)
{
document.getElementById('show_pass').innerHTML="密碼不能為空";
return false;
}else{
if (thisObj.value.length<6)
{
document.getElementById('show_pass').innerHTML="密碼長度不少于6";
return false;
}
document.getElementById('show_pass').innerHTML="";
return true;
}
}
//檢查倆次密碼輸入是否一致
function check_pass(thisObj){
var psw=document.getElementById('pass');
if(psw.value.length==0)
{
document.getElementById('show_pass').innerHTML="密碼不能為空";
return false;
}else{
document.getElementById('show_pass').innerHTML="";
if (thisObj.value!=psw.value)
{
document.getElementById('show_repass').innerHTML="兩次密碼輸入不正確";
return false;
}
document.getElementById('show_repass').innerHTML="";
return true;
}
}
//檢查email是否正確
function check_email(thisObj){
var reg=/^([a-zA-Z\d][a-zA-Z0-9_]+@[a-zA-Z\d]+(\.[a-zA-Z\d]+)+)$/gi;
var rzt=thisObj.value.match(reg);
if(thisObj.value.length==0){
document.getElementById('show_e').innerHTML="Email不能為空";
return false;
}else{
if (rzt==null)
{
document.getElementById('show_e').innerHTML="Email地址不正確";
return false;
}
document.getElementById('show_e').innerHTML="";
return true;
}
}
//檢查qq格式是否正確
function check_qq(thisObj){
var qq=document.getElementById('qq').value;
var reg=/^\d+$/;
if(qq.search(reg))
{
document.getElementById('show_qq').innerHTML=" QQ 只能為數(shù)字";
return false;
}else{
document.getElementById('show_qq').innerHTML="";
return true ;
}
}
作者: sweet__smile
復(fù)制代碼 代碼如下:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link rel="stylesheet" type="text/css" href="css/int.css" />
<script type="text/javascript" src="js/func.js"></script>
<style type="text/css">
td{
height:30px;
vertical-align:middle;
align:center;
}
#myText{
width:600px;
}
</style>
<title>注冊頁面</title>
</head>
<body >
<?php
error_reporting(0);
//不讓PHP報(bào)告有錯(cuò)語發(fā)生。如果不關(guān)閉好有類似這的錯(cuò)語 Warning: preg_match() 關(guān)閉就不出現(xiàn)了
session_start();
header("Cache-control: private");
$conn = @ mysql_connect("localhost","root","")or die("數(shù)據(jù)庫連接錯(cuò)誤");
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 "<script type='text/javascript'>alert('用戶名已存在');location='javascript:history.back()';</script>";
}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 "<script type='text/javascript'>alert('寫入成功??!');location.href='login.php';</script>";
}
//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><input id="username" name="username" class="myText" type="text" maxlength="12" /></td>
</tr>
<tr> <!--性別:0 保密 1 女 2 男-->
<td > 性別:</td>
<td>女<input type="radio" value="1" name="sex"/>
男<input type="radio" value="2" name="sex" />
保密<input type="radio" value="0" name="sex" checked/></td>
</tr>
<tr>
<td>密碼:</td><td><input name="pass" class="myText" type="password" onblur="check_len(this)"/><span id="show_pass" style="color:red;"></span></td>
</tr>
<tr>
<td>重復(fù)密碼:</td><td><input name="repass" class="myText" type="password" onblur="check_pass(this)" /><span id="show_repass" style="color:red;"></span></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"></span></td>
</tr>
<tr>
<td>郵箱:</td><td><input type="text" class="myText" name="email" onblur="check_email(this)"/><span id="show_e" style="color:red;"></span></td>
</tr>
<tr>
<td height="60">頭像:</td>
<td>
<select name="img_select" onchange="img_change(this)">
<option value="101" >女 001</option>
<option value="102" >女 002</option>
<option value="103" >女 003</option>
<option value="104" >女 004</option>
<option value="105" >男 001</option>
<option value="106" >男 002</option>
<option value="107" >男 003</option>
<option value="108" >男 004</option>
</select>
<img src="/bbs/img/101.gif" id="tx_change" style="width:50px; height:65px;" alt=""/>
</td>
</tr>
<tr height="20" align="justify">
<td align="right" ><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">我已有賬號(hào)現(xiàn)在<a href="login.php">登錄</a></td>
</tr>
</table>
</form>
</body>
</html>
func.js
復(fù)制代碼 代碼如下:
//根據(jù)下拉框變換圖片
function img_change(thisObj){
var imgsrc = "/bbs/img/"+ thisObj.value+".gif";
document.getElementById("tx_change").src=imgsrc;
}
//檢查是否都符合 注冊 要求
function check_reg()
{
if(check_len() && check_pass() && check_email() && check_qq())
{
return true;
}else{
return false;
}
}
//檢查密碼長度不能少于6
function check_len(thisObj){
if(thisObj.value.length==0)
{
document.getElementById('show_pass').innerHTML="密碼不能為空";
return false;
}else{
if (thisObj.value.length<6)
{
document.getElementById('show_pass').innerHTML="密碼長度不少于6";
return false;
}
document.getElementById('show_pass').innerHTML="";
return true;
}
}
//檢查倆次密碼輸入是否一致
function check_pass(thisObj){
var psw=document.getElementById('pass');
if(psw.value.length==0)
{
document.getElementById('show_pass').innerHTML="密碼不能為空";
return false;
}else{
document.getElementById('show_pass').innerHTML="";
if (thisObj.value!=psw.value)
{
document.getElementById('show_repass').innerHTML="兩次密碼輸入不正確";
return false;
}
document.getElementById('show_repass').innerHTML="";
return true;
}
}
//檢查email是否正確
function check_email(thisObj){
var reg=/^([a-zA-Z\d][a-zA-Z0-9_]+@[a-zA-Z\d]+(\.[a-zA-Z\d]+)+)$/gi;
var rzt=thisObj.value.match(reg);
if(thisObj.value.length==0){
document.getElementById('show_e').innerHTML="Email不能為空";
return false;
}else{
if (rzt==null)
{
document.getElementById('show_e').innerHTML="Email地址不正確";
return false;
}
document.getElementById('show_e').innerHTML="";
return true;
}
}
//檢查qq格式是否正確
function check_qq(thisObj){
var qq=document.getElementById('qq').value;
var reg=/^\d+$/;
if(qq.search(reg))
{
document.getElementById('show_qq').innerHTML=" QQ 只能為數(shù)字";
return false;
}else{
document.getElementById('show_qq').innerHTML="";
return true ;
}
}
作者: sweet__smile
您可能感興趣的文章:
- PHP+Ajax異步通訊實(shí)現(xiàn)用戶名郵箱驗(yàn)證是否已注冊( 2種方法實(shí)現(xiàn))
- php發(fā)送短信驗(yàn)證碼完成注冊功能
- php用戶注冊頁面利用js進(jìn)行表單驗(yàn)證具體實(shí)例
- php用戶注冊信息驗(yàn)證正則表達(dá)式
- 用Php編寫注冊后Email激活驗(yàn)證的實(shí)例代碼
- php自動(dòng)注冊登錄驗(yàn)證機(jī)制實(shí)現(xiàn)代碼
- PHP學(xué)習(xí)筆記 用戶注冊模塊用戶類以及驗(yàn)證碼類
- Thinkphp實(shí)現(xiàn)短信驗(yàn)證注冊功能
- php 注冊時(shí)輸入信息驗(yàn)證器的實(shí)現(xiàn)詳解
- php+ajax注冊實(shí)時(shí)驗(yàn)證功能
- js和php郵箱地址驗(yàn)證的實(shí)現(xiàn)方法
- PHP實(shí)現(xiàn)的激活用戶注冊驗(yàn)證郵箱功能示例
相關(guān)文章
ThinkPHP5+UEditor圖片上傳到阿里云對象存儲(chǔ)OSS功能示例
這篇文章主要介紹了ThinkPHP5+UEditor圖片上傳到阿里云對象存儲(chǔ)OSS功能,結(jié)合實(shí)例形式分析了ThinkPHP5使用富文本編輯器UEditor實(shí)現(xiàn)圖片上傳到阿里云的相關(guān)操作技巧,需要的朋友可以參考下2019-08-08php上傳文件,創(chuàng)建遞歸目錄的實(shí)例代碼
這篇文章介紹了php上傳文件,創(chuàng)建遞歸目錄的實(shí)例代碼,有需要的朋友可以參考一下2013-10-10laravel 解決paginate查詢多個(gè)字段報(bào)錯(cuò)的問題
今天小編就為大家分享一篇laravel 解決paginate查詢多個(gè)字段報(bào)錯(cuò)的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10關(guān)于laravel5.5的定時(shí)任務(wù)詳解(demo)
今天小編就為大家分享一篇關(guān)于laravel5.5的定時(shí)任務(wù)詳解(demo),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10PHPStorm 2020.1 調(diào)試 Nodejs的多種方法詳解
這篇文章主要介紹了PHPSTORM 2020.1 調(diào)試 Nodejs的多種方法詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09Windows下部署Apache+PHP+MySQL運(yùn)行環(huán)境實(shí)戰(zhàn)
本來嘛,部署PHP沒什么復(fù)雜,找各種版本著實(shí)頭疼了一下。2012-08-08Yii2使用小技巧之通過 Composer 添加 FontAwesome 字體資源
前天幫同事改個(gè)十年前的網(wǎng)站 bug,頁面上一堆 include require 不禁讓人抱頭痛哭??吹?V2EX 上的討論說,寫 PHP 不用框架等同于耍流氓。Yii Framework 是我使用了 2 年多的 PHP 框架,器大活好,皮實(shí)耐操。 Yii2 還在 Beta 中,不過不影響拿來預(yù)研。2014-06-06