首页 > 代码库 > php-> msql 修改

php-> msql 修改

修改
<?php
    $code = $_GET["c"];
    //造连接对象
    $db = new MySQLi("localhost","root","123","mydb");
    //写SQL语句
    $sinfo = "select * from info where code=‘{$code}‘";    

    $rinfo = $db->query($sinfo);
    
    $ainfo = $rinfo->fetch_row();
?>

<form action="xiugaichuli.php" method="post">
    <div><input type="hidden" name="code" value=http://www.mamicode.com/"<?php echo $ainfo[0]; ?>" /></div>
    <div>姓名:<input type="text" name="name" value=http://www.mamicode.com/"<?php echo $ainfo[1]; ?>" /></div>
    
    
    
    <div>性别:
    <input type="radio" name="sex" value=http://www.mamicode.com/"1" <?php echo $ainfo[2]?"checked=‘checked‘":"" ?> />&nbsp;
    <input type="radio" name="sex" value=http://www.mamicode.com/"0" <?php echo $ainfo[2]?"":"checked=‘checked‘" ?> /></div>
    
    
    
    <div>民族:
    <select name="nation">
        <?php
        
        $sql = "select * from nation";
        $result = $db->query($sql);
        $attr = $result->fetch_all();
        
        foreach($attr as $v)
        {
            if($v[0]==$ainfo[3])
            {
                echo "<option selected=‘selected‘ value=http://www.mamicode.com/‘{$v[0]}‘>{$v[1]}";
            }
            else
            {
                echo "<option value=http://www.mamicode.com/‘{$v[0]}‘>{$v[1]}";
            }
        }
        ?>
    </select>
    </div>
    
    
    
    <div>生日:<input type="text" name="birthday" value=http://www.mamicode.com/"<?php echo $ainfo[4]; ?>" /></div>
    
    <div><input type="submit" value=http://www.mamicode.com/"修改" /></div>
</form>

修改处理
<?php
$code = $_POST["code"];
$name = $_POST["name"];
$sex = $_POST["sex"];
$nation = $_POST["nation"];
$birthday = $_POST["birthday"];

//造连接对象
$db = new MySQLi("localhost","root","123","mydb");

$sql = "update info set name=‘{$name}‘,sex={$sex},nation=‘{$nation}‘,birthday=‘{$birthday}‘ where code=‘{$code}‘";

$db->query($sql);

header("location:main.php");

 

 

 

 

php-> msql 修改