PHP Data Access (Modify)

Source: Internet
Author: User

Modified: Similar to add, need to display default values

Embed PHP code query database First

$code $_get ["C"]; $db New Mysqli ("localhost", "root", "159357", "Renyuanxinxi"); $ainfo = "SELECT * from info where code= ' {$code} '"; $binfo $db->query ($ainfo); $cinfo $binfo->fetch_row ();

Display the queried values in the Web page (embed the appropriate short PHP code in the form to assign the settings)

<form action= "xiugaichuli.php" method= "POST" > <div><input type= "hidden" name= "code" value= "<?php Echo$ainfo[0];?> "/></div> <div> name: <input type=" text "name=" name "value=" <?php Echo$ainfo[1];?> "/></div> <div> Gender://true false to determine<input type= "Radio" name= "Sex" value= "1" <?phpEcho $ainfo[2]? " Checked= ' checked ' ":" "?>/>male&nbsp; <input type= "Radio" name= "Sex" value= "0" <?phpEcho $ainfo[2]? "": "checked= ' checked '"?>/>female</div> <div>Ethnicity:<select name= "Nation" > <?PHP$sql= "SELECT * From Nation"; $result=$db->query ($sql); $attr=$result-Fetch_all (); foreach($attr  as $v)//Drop- down list set default        {            if($v[0]==$ainfo[3])            {                Echo"<option selected= ' selected ' value= ' {$v[0]} ' >{$v[1]} </option> "; }            Else            {                Echo"<option value= ' {$v[0]} ' >{$v[1]} </option> "; }        }        ?> </select> </div> <div> Birthdays: <input type= "text" name= "Birthday" value= "<?ph P Echo$ainfo[4];?> "/></div> <div><input type=" Submit "value=" Modify "/></div></form>

Create a modification processing page (value First, then modify the statement to select the column to be modified based on the primary key value, and then execute)

<?PHP$code=$_post["Code"];//Take value$name=$_post["Name"];$sex=$_post["Sex"];$nation=$_post["Nation"];$birthday=$_post["Birthday"];$db=NewMysqli ("localhost", "root", "159357", "Renyuanxinxi");$sql= "Update info set name= ' {$name} ', sex={$sex},nation= ' {$nation} ', birthday= ' {$birthday} ' where code= ' {$code}‘";//Select the column you want to modify with a modified statement based on the primary key value$db->query ($sql);//ExecutionHeader("location:main.php");

PHP Data Access (Modify)

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.