zoukankan      html  css  js  c++  java
  • 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 "修改失败";    
    }
    ?>
  • 相关阅读:
    git add 添加错文件 撤销
    ArcMap中对失量数据将具有相同的字段的元素进行合并
    win10系统黑屏无法显示桌面解决
    C#
    git push的时候报错: Out of memory, malloc failed (tried to allocate 82037333 bytes)
    在abp core中出现运行项目时EF获取到的appsetting.json或者appsettings.Production.json中的连接字符串为空
    navicat连接数据库报错:未发现数据源名称并且未指定默认驱动程序
    HDU
    HDU
    HDU
  • 原文地址:https://www.cnblogs.com/qz1234/p/5582776.html
Copyright © 2011-2022 走看看