2016-12-19 php修改資料庫資料

來源:互聯網
上載者:User

標籤:網頁   method   nat   turn   order   test   info   new   cin   

讓info表在網頁中顯示

<h1>人員表</h1>
<table width="100%" cellpadding="opx" cellspacing="0px" border="1px">
<tr>
<td>代號</td>
<td>姓名</td>
<td>性別</td>
<td>民族</td>
<td>生日</td>
<td>操作</td>


</tr>

<?php
$db=new MySQLi("localhost","root","222","test");
$sql= "select * from info";
$result=$db->query($sql);
$attr=$result->fetch_all();
foreach($attr as $v)
{
$sex = $v[2];
$sex = $sex?"男":"女";

$nation = $v[3];
$sqln = "select name from nation where code=‘{$nation}‘";
$rn = $db->query($sqln);
$an = $rn->fetch_row();


echo"<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$sex}</td><td>{$an[0]}</td><td>{$v[4]}</td>
<td><a href=‘xiugai.php?code=$v[0] ‘ onclick=\"return confirm(‘真的要修改麼‘)\">修改<a></td></tr>";
}

 

 

?>
</table>

做修改頁面

<h1>修改頁面</h1>
<form action="xiugaichuli.php" method="post">
<div><input type="hidden" name="code" value="<?php echo $attr[0] ?>"name="code" /></div>
<div>姓名:<input type="text" name="name" value="<?php echo $attr[1] ?>" /></div>
<div>性別:<input type="radio" name="sex" value="1"<?php echo $attr[2]?" checked=‘checked‘":"" ; ?> />男<input type="radio" name="sex"value="0" <?php echo $attr[2]?"":"checked=‘checke‘" ?> />女</div>
<div>民族:
<select name="nation">
<?php
$sqln = "select * from nation";
$rn = $db->query($sqln);
$an = $rn->fetch_all();
foreach($an as $vn)
{
if($attr[3]==$vn[0])
{
echo "<option selected=‘selected‘ value=‘{$vn[0]}‘>{$vn[1]} >{$vn[1]}</option>";
}
else
{
echo "<option value=‘{$vn[0]}‘>{$vn[1]}</option>";
}
}
?>
</select>
</div>
<div>生日:<input type="text" name="birthday" value=" <?php echo $attr[4] ?> " /></div>
<div><input type="submit" value="確認修改" /></div>
</form>

修改處理頁面

<?php
$code = $_POST["code"];
$name = $_POST["name"];
$sex = $_POST["sex"];
$nation = $_POST["nation"];
$birthday = $_POST["birthday"];
$db = new MySQLi("localhost","root","222","test");
$sql = "update info set name=‘{$name}‘,sex={$sex},nation=‘{$nation}‘,birthday=‘{$birthday}‘ where code=‘{$code}‘";
$r = $db->query($sql);
echo $sql;
if($r)
{

header("location:main.php");
}
else
{
echo "修改失敗!";
}
?>

 

把胡軍得資訊改了以後

2016-12-19 php修改資料庫資料

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.