Make changes to the database from the Web page, connect the previous Add, delete, check.
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 to add the page code to copy over -
<?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?>
<formAction= "xiugaichuli.php"Method= "POST"><!--submit the form to the xiugaichuli.php page. - <Div><inputtype= "hidden"name= "Code"value= "<?php echo $ainfo [0];?>" /></Div><!--The value of the default value of the code name is displayed as the value of the code name of the data to be changed, and 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 directly hidden, directly type=hidden, although hidden, but can also be submitted - <Div>Name:<inputtype= "text"name= "Name"value= "<?php echo $ainfo [1];?>" /></Div><!--principle and Code - <!--gender and ethnicity cannot be directly given a value, which needs to be selected according to the value - <!--sex is a Boer data, either 0 or 1.php the function of the code inside is to remove the code inside the $info, to determine whether the gender is true or flase, is true if the output property checked= "Checked", is flase output empty - <Div>Gender:<inputtype= "Radio"name= "Sex"value= "1"<?php echo $ainfo [2]? " Checked= ' checked ' ": " "?>/> Male <inputtype= "Radio"name= "Sex"value= "0"<?php echo $ainfo [2]? ":" Checked= ' checked ' "?>/> Women</Div> <!--National is a drop-down list, drop-down list is selected with the attribute selected=selected, the drop-down option is a foreach traversal, before the output can be judged to modify the person's code is equal to the output of this item code - <Div>Ethnicity:<Selectname= "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> <Div>Birthday:<inputtype= "text"name= "Birthday"value= "<?php echo $ainfo [4];?>" /></Div><!--principle and Code - <Div><inputtype= "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");
10.31 a.m. changes to the database (implementation of changes to the database from the Web page)