reg.php
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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> Registration Page </title>
<body >
<?php
error_reporting (0);
Do not let PHP report the wrong language to occur. If it's not closed, there's a wrong language like this. warning:preg_match () shut down.
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 "<script type= ' text/javascript ' >alert (' username already exists '); 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 (' Write success!! '); 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> User: </td><td><input id= "username" name= "username" class= "myText" type= "text" maxlength= "12" /></td>
</tr>
<tr> <!--sex: 0 Confidential 1 female 2 male-->
<TD > Gender:</td>
<td> female <input type= "Radio" value= "1" name= "Sex"/>
Male <input type= "Radio" value= "2" name= "Sex"/>
Confidential <input type= "Radio" value= "0" name= "Sex" checked/></td>
</tr>
<tr>
<td> Password: </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> duplicate Password: </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> e-mail: </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= > Avatar:</td>
<td>
<select name= "Img_select" onchange= "Img_change (This)" >
<option value= "001</option>" > Female
<option value= "102" > Female 002</option>
<option value= "003</option>" > Female
<option value= "> Female 004</option>"
<option value= > Male 001</option>
<option value= "002</option>" > Male
<option value= "003</option>" > Male
<option value= "108" > Male 004</option>
</select>
</td>
</tr>
<tr height= "align=" Justify ">
<TD align= "right" ><input type= "Submit" value= "registered" Name= "submit" style= "MARGIN-RIGHT:5PX;" /></td>
<td><input type= "reset" value= "reset" name= "reset" style= "margin-left:5px". /></td>
</tr>
<tr>
<TD colspan= "2" > I have my account now <a href= "login.php" > Login </a></td>
</tr>
</table>
</form>
</body>
Func.js
Copy Code code as follows:
To transform a picture according to the dropdown box
function Img_change (thisobj) {
var imgsrc = "/bbs/img/" + thisobj.value+ ". gif";
document.getElementById ("Tx_change"). Src=imgsrc;
}
Check to see if all the registration requirements are met
function Check_reg ()
{
if (Check_len () && check_pass () && check_email () && check_qq ())
{
return true;
}else{
return false;
}
}
Check password length must not 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 not less than 6";
return false;
}
document.getElementById (' Show_pass '). innerhtml= "";
return true;
}
}
Check that the password input is consistent between two times
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= "Two times password input is incorrect";
return false;
}
document.getElementById (' Show_repass '). innerhtml= "";
return true;
}
}
Check to see if the email is correct
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 cannot be empty";
return false;
}else{
if (rzt==null)
{
document.getElementById (' Show_e '). innerhtml= "Incorrect email address";
return false;
}
document.getElementById (' Show_e '). innerhtml= "";
return true;
}
}
Check 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 digital";
return false;
}else{
document.getElementById (' Show_qq '). innerhtml= "";
return true;
}
}
Author: sweet__smile