php-Database Access--Add, delete, change

Source: Internet
Author: User

Create a Test form

<form action= "chuli.php" method= "POST" > <div> user name: <input type= "text" name= "UID"/></div> < div> Password: <input type= "password" name= "pwd"/></div> <div><input type= "Submit" value= "Login"/> </div></form>Chuli.PHP<?PHP$_post["UID"];$_post["PWD"];//Connecting Objects$db=NewMysqli ("localhost", "root", "123", "MyDB");//Write SQL statements$sql= "Select password from login Shere uid= ' {$uid}‘";//Execute SQL statement$resulat=$db->query ($sql);$n=$result-Fetch_row ();//Judging
if ($uid! = "" && $pwd! = ")
{if($n[0]==$PSD) {Header(Location:main.php);}Else{Echo"User name or password error";}

Else
{
echo "User name or password cannot be empty";
}



/*Write SQL statements, unsafe login methods
Injection Attack $sql = "SELECT count (*) from login where useename= ' {$uid} ' and passwoed= ' {$pwd} '";//Execute SQL statement $result = $db->qu ery ($sql); $n = $result-fetch_row (); if ($n [0]>0) {header ("location:main.php");} else{echo "username or password error";}*/      

Injection attacks, this type of code is not safe to sign in

php-Database Access--Add, delete, change

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.