PHP Background Add delete modify Jump page

Source: Internet
Author: User

1 the First Step2<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">3"http://www.w3.org/1999/xhtml">45<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>6<title> Untitled Document </title>78   9<body>Ten one<table width="100%"Border="1"cellpadding="0"cellpadding="0"> a<tr> -<td> Code </td> -<td> name </td> the<td> Price </td> -<td> Origin </td> -<td> Inventory </td> -<td> Delete </td> +</tr> -   +<?PHP a  //1. Making linked objects at$db =NewMysqli ("localhost","Root","511108","text"); -  //2. Write SQL statements -$sql ="Select*from Fruit"; -  //3. Implementation -$result = $dbQuery ($sql); -  //4. Read Data (there are two Methods) in  //1. Methods -  /*$attr = $result->fetch_all (); to foreach ($attr as $v) +  { - echo "<tr><td>{$v [0]}</td><td>{$v [1]}</td><td>{$v [2]}</TD><TD >{$v [3]}</td><td>{$v [4]}</td></tr> "; the  *  }*/ $  //2. MethodsPanax Notoginseng   while($attr = $resultFetch_row ()) -  { theEcho"<tr><td>{$attr [0]}</td><td>{$attr [1]}</td><td>{$attr [2]}</td> <td>{$attr [3]}</td><td>{$attr [4]}</td><td> +<a href='shanchu.php?code={$attr [0]}'Onclick=\"return confirm (' OK delete ') \ ' > Delete a</a> the       +<a href='xiugai.php?code={$attr [0]}'> Modify </a>//plus a tag to modify the data in the Table. -       $</td></tr>"; $   -  } -   the  -?>Wuyi</table> the  -<a href="tianjiashuiguo.php"> Add Data </a> wu   -</body> about<script type="Text/javascript"></script> $Donkey label that modified a tag underneath the

Here are the modifications

Step Two1 <! DOCTYPE html public"-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 2 Hidden"name=" IDs "/></div><!--code is not changed, hidden has hidden effects-->12 <div> name: <input type=" text "name=" name "/ ></div>13 <div> price: <input type= "text" name= "prices"/></div>14 <div> origin: <input type = "text" name= "source"/></div>15 <div> stock: <input type= "text" name= "numbers"/></div>16 < Div><input type= "submit" value= "modify"/></div>17 </form>18 </body>21 

Hidden Effect Code Box hidden

Modify the Fruit form page as follows

1 <! DOCTYPE html public"-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 2 PHP11$code=$_get["code"];//take the Cade primary key Value. To query the data12//Create linked Objects13$db=NewMysqli ("localhost", "root", "511108", "text");14//Write SQL statements15$sql= "select * from fruit where ids= ' {$code}‘";//based on the primary key search fruit table IDs primary key code query content16//Execution17$result=$db->query ($sql);18//Fetch Data19$attr=$result->fetch_row ();//according to the primary key value to find out only one data, know that only one data can be directly adjusted $result->fetch_row () it will return an array of the first data, one-dimensional array. 20//the next step is to show $attr this data in the current page after the primary key code IDs with value embedded <?php code, output echo $attr [0] is the code name>24 <form action= "xiugaichuli.php" method= "post" >25 <input type= "hidden" name= "ids" value= "<? PHP Echo$attr[0]?> "/><!--code name does not allow the user to change, hidden-->26 <div>: <input type=" text "name=" name "value=" <?php Echo$attr[1]?> "/></div>27 <div> prices: <input type=" text "name=" price "value=" <?php Echo$attr[2]?> "/></div>28 <div> origin: <input type=" text "name=" source "value=" <?php Echo$attr[3]?> "/></div>29 <div> stock: <input type=" text "name=" numbers "value=" <?php Echo$attr[4]?> "/></div>30 <div><input type=" Submit "value=" Modify "/></div>31 </form>32 </ Body>33  add value after each code name= "<?php echo $attr[0]?> The default values in each text box are as follows

Click Edit Process Page

Step Three

1Click Edit Process Page2 <?PHP3$ids=$_post["ids"]; 4$name=$_post["name"]; 5$price=$_post["price"]; 6$source=$_post["source"]; 7$numbers=$_post["numbers"]; 8//Create linked Objects9$db=NewMysqli ("localhost", "root", "511108", "text");10//Write SQL statement below is a modified statement11//price price={$price} is an integer without single quotation marks. Stock numbers={$numbers} is also an integer that does not require single quotes. Modify the primary key passed over where ids= ' {$ids} '12$sql= "update Fruit Set name= ' {$name} ', price={$price},source= ' {$source} ', numbers={$numbers} where ids= ' {$ids}‘";13//Execution14$r=$db->query ($sql);15if($r)16 {17Header("location:pingguoxinxi.php");//Skip to Main page18 }19Else20 {21stEcho"the modification failed!" "; 22 Run as 1, Figure 2 

Figure 1
Figure 2

PHP Background Add delete modify Jump page

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.