验证用户名是否存在的php代码
Verify username
注册页面之前先验证用户名是否存在的php代码,需要的朋友可以参考下
reg.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)
}
?>
func.js
代码如下:
//根据下拉框变换图片
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{
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 只能为数字";
return false;
}else{
document.getElementById('show_qq').innerHTML="";
return true ;
}
}
作者: sweet__smile
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
1 weeks ago
By DDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
CakePHP Tutorial
1375
52

