1. Query the table of elements, gender show male and female, national display name
2. Add Data
Home:
<!--############################################# #添加数据 ##############################################-->
"0613addchuli.php" code
<?php $code =$_post["code"; $name =$_post["name"]; $sex =$_post["sex"]; $nation =$_post["Nation"; $birthday =$_post ["Birthday"]; $s = $sex ==1? ' True ': ' false ';//no need to process/build objects $db=new mysqli ("localhost", "root", "" "," AAAS ");//Determine if the connection is correct!mysqli_connect_error () or Die (" Link failed! ");//write SQL statement $sql=" INSERT into info values (' {$code} ', ' {$name} ', {$s}, ' {$nation} ', ' {$birthday} ') ';//$s is of type bool, do not add single quotes/ /Execute SQL statement $r= $db->query ($sql), if ($r) { header ("location:0613chaxun.php");} else{ echo "Add failed! ";}
3. Delete data
<!--###################### #删除表中元素 #######################--><table width= "100%" border= "1" cellspacing= "0 "cellpading=" 0 "><tr> <td> code </td> <td> name </td> <td> gender </td> <td& GT, ethnic </td> <td> birthdays </td> <td> operations </td></tr> <? PHP//Early object that $db =new mysqli ("localhost", "root", "" "," AAAS "); Judge Link!mysqli_connect_error () or Die ("Link Error! "); SQL statement $sql = "SELECT * from Info"; Execute SQL statement $result = $db->query ($sql); Read Data $attr = $result->fetch_all (); foreach ($attr as $v) {//gender shows male and female $v[2] $sex = $v [2]? " Male ":" Female "; Judging ethnic $v [3] $sql 1= "SELECT name from Nation where Code= ' $v [3] '"; $re = $db->query ($sql 1); $a = $re->fetch_row (); echo "<tr> <td>{$v [0]}</td> <td>{$v [1]}</td> <td>{$sex}&L t;/td> <td>{$a [0]}</td> <td>{$v [4]}</td> <td><a href= ' 0613delete.php?code={$v [0]} ' > Delete </a></td></tr> '; }?></table>
0613delete.php Code
<?php$code=$_get["Code"]; $db =new mysqli ("localhost", "root", "", "AAAS");! Mysqli_connect_error () or Die ("Understanding failed! $sql = "Delete from info where code= ' {$code} '"; $r = $db->query ($sql); if ($r) { header ("location:0612chaxun.php ");} else{ echo "Delete failed! ";}
4. Modify the data
<!--###################### #修改表中元素 #######################--><table width= "100%" border= "1" cellpadding= "0 "cellspacing=" 0 "><tr> <td> code </td> <td> name </td> <td> gender </td> <TD > Nationalities </td> <td> birthdays </td> <td> actions </td></tr> <?php//Build Objects $d =new mysqli (" LocalHost "," root "," "", "AAAS"); Determine the connection!mysqli_connect_error () or Die ("link failed! "); Construct SQL function ' $sql = ' select * from info '; Perform sol function $result = $db->query ($sql); Read array $attr = $result->fetch_all (); Traversal array foreach ($attr as $v) {//Gender shows men and women $sex = $v [2]? " Male ":" Female "; National Display name $V [3] $sql = "SELECT name from Nation where Code= ' $v [3] '"; $re = $db->query ($sql); $a = $re->fetch_row (); echo "<tr> <td>{$v [0]}</td> <td>{$v [1]}</td> <td>{$sex}&L t;/td> <td>{$a [0]}</td> <td>{$v [4]}</td> <td><a href= ' 0613update.php?code={$v [0]} ' > Modify </a></td></tr> '; }?></table>
0613update.php Code
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
0613updatechuli.php Code
<?php$code=$_post["Code"); $name =$_post["name"]; $sex =$_post["sex"]; $nation =$_post["Nation"]; $birthday =$_post ["Birthday"]; $s = $sex ==1? ' True ': ' false ';//no need to process/build objects $db=new mysqli ("localhost", "root", "" "," AAAS ");//Determine if the connection is correct!mysqli_connect_error () or Die (" Link failed! ");//write SQL statement $sql=" UPDATE info set name= ' {$name} ', sex={$sex},nation= ' {$nation} ', birthday= ' {$birthday} ' where Code= ' {$code} ';//Execute SQL statement $r= $db->query ($sql), if ($r) { header ("location:0613chaxun.php");} else{ echo "Modification failed! ";}
Data Access Examples