1. Login
HTML code
<body><form action= "dlchuli.php" method= "POST" ><div> User name: <input type= "text" name= "UID"/> </div><div> Password: <input type= "text" name= "pwd"/></div><input type= "Submit" value= "Login"/></form></body>
Working with page codes
<?PHPHeader("Content-type:text/html;charset=utf-8");$uid=$_post["UID"];$pwd=$_post["PWD"];$DX=NewMysqli ("localhost", "root", "123", "Nation");!Mysqli_connect_error() or die("Connection Failed");$sql= "Select pwd from Nation1 where uid={$uid}";$result=$DX->query ($sql);$attr=$result-Fetch_row ();if($attr[0]==$pwd){ Header("location:zhuye.php"); }Else{ Echo"Bad password"; }
Method Two:
<?PHPHeader("Content-type:text/html;charset=utf-8");$uid=$_post["UID"];$pwd=$_post["PWD"];$DX=NewMysqli ("localhost", "root", "123", "Nation");!Mysqli_connect_error() or die("Connection Failed");$sql= "SELECT count (*) from Nation1 where uid={$uid} and pwd={$pwd}";$result=$DX->query ($sql);//$result is an array, an object$attr=$result->fetch_row ();//This method is not secure enough to useif($attr[0]>0){ Echo"Back to Main Page";}Else{ Echo"User name password Error"; }
2. Registration
HTML code
<body><form action= "zcchuli.php" method= "POST" ><div> Code: <input type= "text" name= "IDs"/>< /div><div> Name: <input type= "text" name= "name"/></div><div> Nation: <input type= "text" Name= " Nation "/></div><div> Sex: <input type=" Radio "value=" 1 " name=" sex "/> Male <input type=" Radio " Value= "0" name= "sex"/> female </div><br/><input type= "Submit" value= "register"/></form></ Body>
Working with page codes
<?PHPHeader("Content-type:text/html;charset=utf-8");$code=$_post["IDs"];$name=$_post["Name"];$nation=$_post["Nation"];$sex=$_post["Sex"];$s=$sex==1?true:false;//The value is all that is obtained$DX=NewMysqli ("localhost", "root", "123", "Nation");!Mysqli_connect_error() or die("Connection Failed");$sql= "INSERT into nation values ('$code‘,‘$name‘,‘$nation‘,‘$s‘)";$result=$DX->query ($sql);if($result){ Header("location:zhuce.php"); }Else{ Echo"Registration Failed"; }?>
PHP Object-oriented access to database cases-----Login and Registration