PHP增删改查

用表格遍历数据库

</head>

<body>
<table width="100%" border="2" cellpadding="0" cellspacing="0" >
<tr>
<td>代号</td>
<td>姓名</td>
<td>性别</td>
<td>生日</td>
<td>班级</td>
<td>选项</td>
</tr>
<?php

$db = new MySQLi("localhost","root","123","student");

$sql = "select * from student";

$result = $db->query($sql);

$attr = $result->fetch_row();

while($attr= $result->fetch_row())
{
    if($attr[2]==1)
    {
        $attr[2]="男";    
    }
    else
    {
        $attr[2]="女";    
    }
    echo "<tr>
            <td>$attr[0]</td>
            <td>$attr[1]</td>
            <td>$attr[2]</td>
            <td>$attr[3]</td>
            <td>$attr[4]</td>
            <td><a href='shanchu.php?code={$attr[0]}'>删除</a></td>
            <td><a href='xiugai.php?code={$attr[0]}'>修改</a></td>
        </tr>";
}
?>

</table>
</body>
</html>

 

加入修改页面

 

<?php
$code = $_GET["code"];

$db = new MySQLi("localhost","root","123","student");
$sql = "select * from student where sno = '{$code}'";
$result = $db->query($sql);
$attr = $result->fetch_row();
?>
<form action="xiugaichuli.php" method="post">
<div>编号:<input type="text" name="uid" value="<?php echo $attr[0] ?>" readonly="readonly" /></div>
<div>姓名:<input type="text"  name="wnd" 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='checked"; ?>  />女 </div>
<div>生日:<input type="text"  name="shengri" value="<?php echo $attr[3] ?>"/></div>
<div>班级:<input type="text"  name="class" value="<?php echo $attr[4] ?>"/></div>
<input type="submit" value="修改" />
</form>

 

 加入修改处理页面

<?php

$sno = $_POST["uid"];

$name = $_POST["wnd"];

$sex = $_POST["sex"];

$birthday = $_POST["shengri"];

$class = $_POST["class"];

$db = new MySQLi("localhost","root","123","student");

$sql = " update student set sname = '{$name}',ssex = '{$sex}',sbirthday = '{$birthday}',class = '{$class}' where sno = '{$sno}'";

$r = $db->query($sql);

echo $sql;

if($r)
{
        header("location:biaoge.php");
}
else
{
    echo "修改失败";    
}
?>

 

转载于:https://www.cnblogs.com/qz1234/p/5582776.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值