Case: Main page of the additions and deletions to search

Source: Internet
Author: User

Main Page:

Main Page code:

&LT;BODY&GT;&LT;H1 align= "Center" > main Page PHP$db=NewMysqli ("localhost", "root", "123", "info");!Mysqli_connect_error() or die("Connection Failed");$sql= "SELECT * FROM Info";$result=$db->query ($sql);$attr=$result-Fetch_all ();foreach($attr  as $v){    $s=$v[2]==1? ' Male ': ' Female '; $sq= "SELECT name from Nation where Code= ' {$v[3]} ' "; $r=$db->query ($sq); $a=$r-Fetch_row (); Echo"<tr> <td align= ' center ' >{$v[0]}</td> <td align= ' center ' >{$v[1]}</td> <td align= ' center ' >{$s}</td> <td align= ' center ' >{$a[0]}</td> <td align= ' center ' >{$v[4]}</td> <td align= ' center ' ><a href= ' delete.php?code={$v[0]} ' > Delete </a> <a href= ' update.php?code={$v[0]} ' > Modify </a> </td> </tr>";}? ></table><br/><a href= "add.php" > Add Data </a></body>

To add a page:

Add code:

Except for integers, decimals, and bool, the other quotes are quoted.

<form action= "addchuli.php" method= "POST" >Code: <input type= "text" name= "code"/><br/>name: <input type= "text" name= "name"/><br/>Sex: <input type= "Radio" value= "1" name= "sex"/> Male <input type= "Radio" value= "0" name= "sex"/> female <br/>ethnic: <select name= "select" &GT;&LT;?PHP$db=NewMysqli ("localhost", "root", "123", "info"); !Mysqli_connect_error() or die("Connection Error"); $sql= "SELECT * From Nation"; $result=$db->query ($sql); /*while ($attr = $result->fetch_row ()) {echo "<option value= ' {$attr [0]} ' >{$attr [1]}</option>"; }*/    $attr=$result-Fetch_all (); foreach($attr  as $v)    {        Echo"<option value= ' {$v[0]} ' >{$v[1]} </option> "; }    ? ></select><br/>Birthday: <input type= "date" name= "Birthday" ><br/><input type= "Submit" value= "Submit"/></form>

Add Processing page code:

<?PHPHeader("Content-type:text/html;charset=utf-8");$code=$_post["Code"];$name=$_post["Name"];@$sex=$_post["Sex"];$nation=$_post["Select"];$birthday=$_post["Birthday"];$db=NewMysqli ("localhost", "root", "123", "info");!Mysqli_connect_error() or die("Connection Failed");$sql= "INSERT into info values (' {$code}‘,‘{$name}‘,{$sex},‘{$nation}‘,‘{$birthday}‘)";Var_dump($sql);$result=$db->query ($sql);if($result){    Header("location:main.php"); }Else{    Echo"Add Failed";}

Delete Processing page code:

<?PHPHeader("Content-type:text/html;charset=utf-8");$code=$_get["Code"];$db=NewMysqli ("localhost", "root", "123", "info");!Mysqli_connect_error() or die("Connection Failed");$sql= "Delete from info where code= ' {$code}‘";$result=$db->query ($sql);if($result){Header("location:main.php");}Else{Echo"Delete Failed";}

To modify the Display page:

Code: Notice where PHP is embedded

<body><?PHP$code=$_get["Code"];$DX=NewMysqli ("localhost", "root", "123", "info");!Mysqli_connect_error() or die("Connection Failed");$sq= "SELECT * from info where code= ' {$code}‘";$re=$DX->query ($sq);$att=$re-Fetch_row ();? ><form action= "xiugaichuli.php" method= "POST" >Code: <input type= "text" name= "code" readonly= "readonly" value= "<?php Echo$att[0];? > "/><br/>name: <input type= "text" name= "name" value= "<?php Echo$att[1];? > "/><br/>Sex: <input type= "Radio" value= "1" name= "Sex" <?phpEcho $att[2]? " Checked= ' checked ' ":" ";?>/>male<input type= "Radio" value= "0" name= "Sex" <?phpEcho $att[2]? "": "checked= ' checked '";? >/>female<br/>ethnic: <select name= "select" &GT;&LT;?PHP$db=NewMysqli ("localhost", "root", "123", "info"); !Mysqli_connect_error() or die("Connection Error"); $sql= "SELECT * From Nation"; $result=$db->query ($sql); /*while ($attr = $result->fetch_row ()) {echo "<option value= ' {$attr [0]} ' >{$attr [1]}</option>"; }*/    $attr=$result-Fetch_all (); foreach($attr  as $v)    {            if($att[3]==$v[0])        {            Echo"<option value= ' {$v[0]} ' >{$v[1]} </option> "; }            Echo"<option value= ' {$v[0]} ' >{$v[1]} </option> "; }    ? ></select><br/>Birthday: <input type= "text" name= "Birthday" value= "<?php Echo$att[4];? > "/><br/><input type=" Submit "value=" Modify "/></form></body>

To modify the processing page:

<?PHPHeader("Content-type:text/html;charset=utf-8");$code=$_post["Code"];$name=$_post["Name"];$sex=$_post["Sex"];$nation=$_post["Select"];$bir=$_post["Birthday"];$db=NewMysqli ("localhost", "root", "123", "info");!Mysqli_connect_error() or die("Connection Failed");$sql= "Update info set name= ' {$name} ', sex={$sex},nation= ' {$nation} ', birthday= ' {$bir} ' where code= ' {$code}‘";Echo $sql;$result=$db->query ($sql);Var_dump($result);if($result){        Header("location:main.php"); }Else{        Echo"Modify Failed"; }

Case: Main Page additions and deletions

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.