example, establish login interface and create, delete form

Source: Internet
Author: User
Tags sql injection attack

The following is the code for the login box

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Here is the PHP code for processing chuli.php

<?PHP$uid=$_post["UID"];$pwd=$_post["PWD"];//Connecting Objects$db=NewMysqli ("localhost", "root", "123", "MyDB");//Write SQL statement//sql injection attack$sql= "Select password from login where username= ' {$uid}‘";//Execute SQL statement$reslut=$db->query ($sql);$n=$reslut-Fetch_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";}

Here is the main page main.php

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><Tablewidth= "100%"Border= "1"cellpadding= "0"cellspacing= "0">    <TR>        <TD>Code</TD>        <TD>Name</TD>        <TD>Gender</TD>        <TD>National</TD>        <TD>Birthday</TD>        <TD>Operation</TD>    </TR>        <?PHP//Build Connection object $db = new mysqli ("localhost", "root", "123", "MyDB");    Write SQL statement $sql = "SELECT * from Info";    Execute SQL statement $result = $db->query ($sql);        Read Data $attr = $result->fetch_all ();                foreach ($attr as $v) {echo "<tr>"; $sex = $v [2]? "                Male ":" Female ";                Query name family name by 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 nationality code, return national name function Nationname ($code) {//Build Connection object $db = new mysqli ("localhost", "root", "1        "," MyDB ");       Write SQL statement $sql = "SELECT name from Nation where code= ' {$code} '"; Execute SQL statement $result = $db->query ($sql);                $attr = $result->fetch_row ();    return $attr [0];         }?>        </Table><ahref= "add.php"><inputtype= "button"value= "Add Data" /></a></Body></HTML>

The following is the deletion of the shanchu.php

<?PHP$code=$_get["C"];//Connecting Objects$db=NewMysqli ("localhost", "root", "123", "MyDB");$sql= "Delete from info where code= ' {$code}‘";$r=$db->query ($sql);if($r){    Header("location:main.php");}Else{    Echo"Delete Failed";}

And then here's the added interface add.php

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><formAction= "addchuli.php"Method= "POST">    <Div>Code:<inputtype= "text"name= "Code" /></Div>    <Div>Name:<inputtype= "text"name= "Name" /></Div>    <Div>Gender:<inputtype= "Radio"name= "Sex"value= "1"checked= "Checked" />male&nbsp;    <inputtype= "Radio"name= "Sex"value= "0" />female</Div>    <Div>Ethnicity:<Selectname= "Nation">        <?PHP//Build Connection object $db = new mysqli ("localhost", "root", "123", "MyDB");        $sql = "SELECT * From Nation";        $result = $db->query ($sql);                $attr = $result->fetch_all ();        foreach ($attr as $v) {echo "<option value= ' {$v [0]} ' >{$v [1]}</option>"; }        ?>    </Select>    </Div>    <Div>Birthday:<inputtype= "text"name= "Birthday" /></Div>        <Div><inputtype= "Submit"value= "Add" /></Div></form></Body></HTML>

Here is the added PHP code addchuli.php

<?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");

example, establish login interface and create, delete form

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.