Home  >  Article  >  Backend Development  >  PHP code to verify whether the username exists before registering the page_PHP tutorial

PHP code to verify whether the username exists before registering the page_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:17:451058browse

reg.php

Copy code The code is as follows:









注册页面


error_reporting(0);
//不让PHP报告有错语发生。If it is not closed, there will be a typo like this Warning: preg_match() will not appear if it is closed
session_start();
header("Cache-control: private");
$conn = @ mysql_connect( "localhost","root","")or die("Database connection error");
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)
}
?>

< ;table name="reg_table" align="left">

User:


Gender:
FemaleMale
Confidential


Password:


Repeat password:

< ;tr>
QQ:


Email:


Avatar:< /td>










I already have an account nowLogin






func.js
Copy code The code is as follows:

//Change the image according to the drop-down box
function img_change(thisObj){
var imgsrc = "/bbs/img/"+ thisObj.value+".gif";
document.getElementById ("tx_change").src=imgsrc;
}
//Check whether all meet the registration requirements
function check_reg()
{
if(check_len() && check_pass() && check_email () && check_qq())
{
return true;
}else{
return false;
}
}
//Check the password length cannot be less than 6
function check_len(thisObj){
if(thisObj.value.length==0)
{
document.getElementById('show_pass').innerHTML="Password cannot be empty";
return false;
}else{
if (thisObj.value.length<6)
{
document.getElementById('show_pass').innerHTML="Password length is not less than 6";
return false;
}
document.getElementById('show_pass').innerHTML="";
return true;
}
}
//Check two password inputs Is it consistent?
function check_pass(thisObj){
var psw=document.getElementById('pass');
if(psw.value.length==0)
{
document.getElementById ('show_pass').innerHTML="Password cannot be empty";
return false;
}else{
document.getElementById('show_pass').innerHTML="";
if (thisObj .value!=psw.value)
{
document.getElementById('show_repass').innerHTML="The password entered twice was incorrect";
return false;
}
document. getElementById('show_repass').innerHTML="";
return true;
}
}
//Check whether the email is correct
function check_email(thisObj){
var reg= /^([a-zA-Zd][a-zA-Z0-9_]+@[a-zA-Zd]+(.[a-zA-Zd]+)+)$/gi;
var rzt=thisObj.value.match(reg);
if(thisObj.value.length==0){
document.getElementById('show_e').innerHTML="Email cannot be empty";
return false;
}else{
if (rzt==null)
{
document.getElementById('show_e').innerHTML="Email address is incorrect";
return false;
}
document.getElementById('show_e').innerHTML="";
return true;
}
}
//Check whether the qq format is correct
function check_qq (thisObj){
var qq=document.getElementById('qq').value;
var reg=/^d+$/;
if(qq.search(reg))
{
document.getElementById('show_qq').innerHTML=" QQ can only be numbers";
return false;
}else{
document.getElementById('show_qq').innerHTML="";
return true ;
}
}

Author: sweet__smile

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325654.htmlTechArticlereg.php Copy the code as follows: !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....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn