PHP Object-oriented access to database cases-----Login and Registration

Source: Internet
Author: User

1. Login

HTML code

<body><form action= "dlchuli.php" method= "POST" ><div> User name: <input type= "text" name= "UID"/> </div><div> Password: &nbsp;<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.