1.html page
<!DOCTYPE HTML><HTML> <Head> <title>Registered</title> <MetaCharSet= "UTF-8" /> <!--JS Verification - <Scripttype= "Text/javascript">
functionvalidate_required (filed, alerttxt) { with(filed) {if(Value== NULL ||value== "") {alert (alerttxt); return false; } Else { return true; } } } functionValidate_form (thisform) { with(thisform) {if(validate_required (username,"user name cannot be empty") == false) {username.focus (); return false; } if(validate_required (Pass1,"The password cannot be empty") == false) {username.focus (); return false; } if(validate_required (Pass2,"confirm that the password cannot be empty") == false) {username.focus (); return false; } if(Pass1.value!=pass2.value) {alert ("two times password inconsistency"); return false; } } } </Script> </Head><!--onsubmit= "return Validate (This)" is a function of verifying the form. When the Validate () function returns a value of true, the form commits, and vice versa. - <Body> <formonsubmit= "return Validate_form (This)"Action= "jstest.php"Method= "POST"> <Divclass= "1"> <Divclass= "1.1"> <Div> <label>User name</label> </Div> <Div> <inputtype= "text"placeholder= "Please enter user name"name= "username"> </Div> </Div> <Divclass= "1.2"> <Div> <label>Password</label> </Div> <Div> <inputtype= "Password"value=""name= "Pass1"> </Div> </Div> <Divclass= "1.3"> <Div> <label>Confirm Password</label> </Div> <Div> <inputtype= "Password"value=""placeholder=""name= "Pass2"> </Div> </Div> </Div> <Divclass= "2"> <inputtype= "Submit"name= "Sub"ID= "Sub"value= "Register" /> </Div> </form> </Body></HTML>
2.php page
jstest.php
<?Phprequire ("mysql_class.php");//Import Database processing file $db = new MySQL ("localhost", "root", "201122", "UserDB"); if (Isset ($_post[) Sub "])) {//get form data $username = $_post[" username "]; $pass 1 = $_post["Pass1"]; $pass 2 = $_post["Pass2"]; Define ("TABLENAME", "user_zhuce"); Define ("SEL", "where username= ' $username '"); Define ("COLE", "(Username,password,password2)"); Define ("Datee", "(' $username ', ' $pass 1 ', ' $pass 2 ')"); Whether the information is empty $DB-IsNull ($username, $pass 1, $pass 2); Password consistency $db-Issame ($pass 1, $pass 2); if ($pass 1 = = $pass 2) {//query has the same user name $sel = $db, select (TABLENAME, SEL); $row = row ($sel) $db; $r = $row [0]; if ($r = = 1) {echo "<script type=". "\"" . "Text/javascript". "\"" . ">". "Window.alert". "(" . " \"" . "The user name has been registered." "\"" . ")" . ";" . "</script>"; echo "<script type=". "\"" . "Text/javascript". "\"" . ">". "Window.location=". "\"" . "Index.html"."\"" . "</script>"; Exit; }//Insert user Information $insert = $db, insert (TABLENAME, COLE, datee); $sel = $db Select (TABLENAME, SEL); $row = row ($sel) $db; $r = $row [0]; if ($r = = 1) {echo "registered successfully"; } $db, Dbclose (); }}?>
3. Database Processing page
mysql_class.php
<?Phpheader ("Content-type:text/html;charset=utf-8"); class Mysql {private $host; server address private $root; User name private $password; Password private $database; Database name//Initialize class function by constructor Mysql ($host, $root, $password, $database) {$this, host = $host; $this root = $root; $this-Password = $password; $this, database = $database; $this, connect (); } function Connect () {$this-conn = mysql_connect ($this, Host, $this, root, $this-password )//if ($this->conn) {//echo "connection MySQL succeeded";//}else{//echo "connection MySQL failed";//}// $this->conn= mysql_select_db ($this, Database, $this-conn);//if ($this->conn) {// echo "Connection db succeeded";//}else{//echo "Connection db failed";/} mysql_query ("Set names UTF8"); } function Dbclose () {mysql_close ($this, conn); } function Query ($sql) {return mysql_query ($sql); } function row ($result) {return mysql_fetch_row ($result); The function Select ($tableName, $condition) {return $this, query ("Select COUNT (*) from $tableName $c Ondition "); } function Insert ($tableName, $fields, $value) {$this, query ("INSERT INTO $tableName $fields values$value" ); } function IsNull ($input 1, $input 2, $input 3) {if ($input 1== "" "| | $input 2== "" | | $input 3== "") {echo "<script type=". " \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Please fill in full (PHP)! "." \"".")".";"." </script> "; }} function Issame ($password 1, $password 2) {if ($password 1!= $password 2) {echo "<script type=" ." \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Two times the password is inconsistent! (PHP) "." \"".")".";"." </script> "; } }}?>
JavaScript Verification Front-end page