The first step
1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9Ten<table width= "100%" border= "1" cellpadding= "0" cellpadding= "0" > One<tr> A<td> Code </td> -<td> name </td> -<td> Price </td> the<td> Origin </td> -<td> Inventory </td> -<td> Delete </td> -</tr> + -<?PHP + //1. Making linked Objects A $db=NewMysqli ("localhost", "root", "511108", "text"); at //2. Write SQL statements - $sql= "Select*from Fruit"; - //3. Implementation - $result=$db->query ($sql); - //4. Read data (There are two methods) - //1. Methods in /*$attr = $result->fetch_all (); - foreach ($attr as $v) to { + 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. Methods $ while($attr=$result-Fetch_row ())Panax Notoginseng { - Echo"<tr><td>{$attr[0]} </td><td>{$attr[1]} </td><td>{$attr[2]} </td><td>{$attr[3]} </td><td>{$attr[4]}</td><td> the<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> //Add a tag to modify the data inside the table + -</td></tr> "; $ $ } - - the?> -</table>Wuyi the<a href= "tianjiashuiguo.php" > Add Data </a> - Wu</body> -<script type= "Text/javascript" ></script> About
Greenword tag that's a modified a tag below is
Here are the modifications
Step Two
1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9Ten<form action= "xiugaichuli.php" method= "POST" > One<div> code: <input type= "Hidden"Name=" IDs "/></div><!--code name does not allow users to change, hidden have hidden effects-- A<div> Name: <input type= "text" name= "name"/></div> -<div>: <input type= "text" name= "Price"/></div> -<div> Origin: <input type= "text" Name= "Source"/></div> the<div> Stock: <input type= "text" name= "Numbers"/></div> -<div><input type= "Submit" value= "Modify"/></div> -</form> - + -</body> +Hidden The Effect code box hide it
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" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9Ten<?PHP One $code=$_get["Code"];//take the Cade primary key value. To query the data A //Build linked objects - $db=NewMysqli ("localhost", "root", "511108", "text"); - //Write SQL statements the $sql= "SELECT * from fruit where ids= ' {$code}‘";//based on the primary key search fruit table IDs primary key code query content - //Execute - $result=$db->query ($sql); - //Fetch Data + $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. - //The next step is to $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 + A at?> -<form action= "xiugaichuli.php" method= "POST" > -<input type= "hidden" name= "IDs" value= "<?php Echo$attr[0]?> "/><!--code name does not allow users to change,hidden--> -<div> Name: <input type= "text" name= "name" value= "<?php Echo$attr[1]?> "/></div> -<div> prices: <input type= "text" name= "price" value= "<?php Echo$attr[2]?> "/></div> -<div> Origin: <input type= "text" Name= "Source"Value=" <?php Echo$attr[3]?> "/></div> in<div> Stock: <input type= "text" name= "Numbers" value= "<?php Echo$attr[4]?> "/></div> -<div><input type= "Submit" value= "Modify"/></div> to</form> +</body> -add value= "<?php echo $attr [0] after each code name the default values in each text box are as follows: ?>
Click Edit Process Page
Step Three
1 Click 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");Ten //Write SQL statement below is a modified statement One //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} ' A $sql= "Update fruit set name= ' {$name} ', price={$price},source= ' {$source} ', numbers={$numbers} where ids= ' {$ids}‘"; - //Execution - $r=$db->query ($sql); the if($r) - { - Header("location:pingguoxinxi.php");//Skip to Main page - } + Else - { + Echo"The modification failed!" "; A}
operating effects such as 1, figure 2
Fig. 1 Fig. 2
PHP Background Add Delete modify jump.