PHP->masql Login and delete changes

Source: Internet
Author: User
Tags sql injection

Login<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>Login Processing<?Php$uid= $_post["UID"]; $pwd= $_post["pwd"];//Connecting Objects$db =NewMysqli ("localhost","Root","123","MyDB");//Write SQL statements//SQL injection Attacks$sql="Select password from login where username= ' {$uid} '";//Execute SQL statement$reslut = $dbquery ($sql); $n= $reslutFetch_row ();if($uid! =""&& $pwd! ="" ){    if($n [0]==$pwd) {Header ("location:main.php"); }    Else{echo"The user name or password is wrong! "; }}Else{echo"User name password cannot be empty";} Data Display<body><table width="100%"Border="1"cellpadding="0"cellspacing="0"> <tr> <td> code </td> <td> name </td> <td> sex </td> &lt ;td> nationalities </td> <td> Birthdays </td> <td> actions </td> </tr> <?PHP//Connecting Objects$db =NewMysqli ("localhost","Root","123","MyDB"); //Write SQL statements$sql ="SELECT * FROM Info"; //Execute SQL statement$result = $dbquery ($sql); //Read Data$attr = $resultFetch_all (); foreach($attr as$v) {echo"<tr>"; $sex= $v [2]?"male":"female"; //Query name family name based on name Family Code$name = Nationname ($v [3]); Echo"<td>{$v [0]}</td><td>{$v [1]}</td><td>{$sex}</td><td>{$name}</ td><td>{$v [4]}</td><td><a href= ' shanchu.php?c={$v [0]} ' onclick=\ ' return confirm (' OK to delete? ') \ > Delete </a></td>"; /*foreach ($v as $v 1) {echo "<td>{$v 1}</td>"; }*/Echo"</tr>"; }        //give a national code, return the name of the Nationfunction Nationname ($code) {//Connecting Objects$db =NewMysqli ("localhost","Root","123","MyDB"); //Write SQL statements$sql ="select name from Nation where code= ' {$code} '"; //Execute SQL statement$result = $dbquery ($sql); $attr= $resultFetch_row (); return$attr [0]; }        ?> </table><a href="add.php"><input type="Button"Value="Add Data"/></a></body>Delete<?Php$code= $_get["C"];//Connecting Objects$db =NewMysqli ("localhost","Root","123","MyDB"); $sql="Delete from info where code= ' {$code} '"; $r= $dbquery ($sql);if($r) {header ("location:main.php");}Else{echo"Delete Failed";} Modify<form action="addchuli.php"Method="Post"> <div> Code: <input type="text"Name="Code"/></div> <div> Name: <input type="text"Name="name"/></div> <div>Gender:<input type="Radio"Name="Sex"Value="1" checked="checked"/>male&nbsp; <input type="Radio"Name="Sex"Value="0"/>female</div> <div>Ethnicity:<SelectName="Nation"> <?PHP//Connecting Objects$db =NewMysqli ("localhost","Root","123","MyDB"); $sql="SELECT * FROM Nation"; $result= $dbquery ($sql); $attr= $resultFetch_all (); foreach($attr as$v) {echo"<option value= ' {$v [0]} ' >{$v [1]}</option>"; }        ?> </Select> </div> <div> Birthdays: <input type="text"Name="Birthday"/></div> <div><input type="Submit"Value="Add"/></div></form></body>Modify Processing<?Php$code= $_post["Code"]; $name= $_post["name"]; $sex= $_post["Sex"]; $nation= $_post["Nation"]; $birthday= $_post["Birthday"];//Connecting Objects$db =NewMysqli ("localhost","Root","123","MyDB"); $sql="INSERT into info values (' {$code} ', ' {$name} ', {$sex}, ' {$nation} ', ' {$birthday} ')"; $db-query ($sql); Header ("location:main.php"); 

PHP->masql Login and delete changes

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.