Make changes to the database from the Web page, connecting the previous additions, deletions, and queries.
1. Make a change page first
<body><!--This page needs to let the user see some data, so not a pure PHP page, the page effect and the effect of increasing the page is very similar, directly copy the code to add the page--
<?php//embed PHP code query database First$code=$_get["C"];//The value of C that is passed when you click Edit .$db=NewMysqli ("localhost", "root", "666", "Text1");//directly to the following build connection object to the above, a page made one can. Write the SQL statement, below has $sql, here writes $info. $sinfo= "SELECT * from info where code= ' {$code}‘";//based on the primary key value, only one data can be found. $rinfo=$db->query ($sinfo);$ainfo=$rinfo->fetch_row ();//take to Array?>
<form action= "xiugaichuli.php" method= "post" ><!--form submitted to xiugaichuli.php page. --<div><input type= "hidden" name= "code" value= "<?php Echo$ainfo[0];?> "/></div><!--the value of the default value of the code is displayed as the value of the code of the data to be changed, the output is OK, the output is empty. The primary key is generally not allowed to be modified, it can be added to the attribute readonly= "ReadOnly". Cannot use disabled=disabled because the form cannot be submitted after setting this property. If the primary key value is a self-growing column or other meaningless column, it can be hidden directly, Type=hidden, although hidden, but can also be submitted--<div> name: <input type= "text" name= "name" Value= "<?php Echo$ainfo[1];?> "/></div><!--principle with code--<!--gender and ethnicity cannot be directly given a value, which needs to be selected according to the value--<!--sex is the data of the Boer type, or 0 or 1 The function of the code inside PHP is to take outthe code inside $info, to determine whether the gender is true or flase, is true if the output attribute checked= "Checked", is the flase output empty--<div>Gender:<input type= "Radio" name= "Sex" value= "1" <?phpEcho $ainfo[2]? " Checked = ' checked ' ":" "?>/>male <input type= "Radio" name= "Sex" value= "0" <?phpEcho $ainfo[2]? "": "checked = ' checked '"?>/>female</div> <!--people are drop-down lists, drop-down lists are selected=selected with attributes, and drop-down options are traversed with foreach, before the output can be judged by the name of the person to be modified is equal to the output of this item code--&G T <div>Ethnicity:<select name= "Nation" >
<?PHP//Connecting Objects $sql= "SELECT * From Nation"; $result=$db->query ($sql); $attr=$result-Fetch_all (); foreach($attr as $v)//determine if the code name of the person to be modified is equal to the name of the item to be exported . { if($v[0]==$ainfo[3]) { Echo"<option selected= ' selected ' value= '$v[0] ' >{$v[1]} </option> ";//output a selected= ' selected ' option for equality } Else { Echo"<option value= '$v[0] ' >{$v[1]} </option> ";//not equal to output a normal option } } ?>
</select> </div> $ainfo[4];?> "/></div><!--Principle and code--- < Div><input type= "Submit" value= "Modify"/></div></form></body>
2.xiugaichuli.php page
<?PHP$code=$_post["Code"];//Remove the 5 values submitted$name=$_post["Name"];$sex=$_post["Sex"];$nation=$_post["Nation"];$birthday=$_post["Birthday"];//Connecting Objects$db=NewMysqli ("localhost", "root", "666", "Text1");$sql= "Update info set name= ' {$name} ', sex={$sex},nation= ' {$nation} ', birthday= ' {$birthday} ' where code= ' {$code}‘";//Modify The time no matter how many changes, all must be changed into the current input. $db->query ($sql);Header("location:main.php");
October 30 Morning modification of the database (implementation of changes to the database from the Web page)