zoukankan      html  css  js  c++  java
  • CRUD

    CRUD

    主界面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    
    </head>
    
    <body>
    
    <table class="table table-striped">
      <caption>人员信息展示</caption>
      <thead>
        <tr>
          <th>代号</th>
          <th>姓名</th>
          <th>性别</th>
          <th>民族</th>
          <th>生日</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
          <?php
        $db = new MySQLi("localhost","root","123","mydb");
        $sql = "select info.code,info.name,sex,nation.name,birthday from info,nation where info.nation=nation.code";
        $result = $db->query($sql);
        if($result){
            $arr = $result->fetch_all();
            foreach($arr as $v){
                $sex = $v[2]?"":"";
                echo "<tr>
          <td>{$v[0]}</td>
          <td>{$v[1]}</td>
          <td>{$sex}</td>
          <td>{$v[3]}</td>
          <td>{$v[4]}</td>
          <td><a href='./delete.php?code={$v[0]}' onclick="return confirm('确认删除么?')"><button type='button' class='btn btn-primary btn-sm'>删除</button></a><a href='.xiugai.php?code={$v[0]}'><button type='button' class='btn btn-primary btn-sm'>修改<button></a></td>
        </tr>";
            }
        }
        ?>
      </tbody>
    </table>
    
    <div><a href="./tianjia.php">添加数据</a></div>
    
    </body>
    </html>

    添加界面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    </head>
    
    <body>
    <h1>添加数据</h1>
    
    <form action="./add.php" method="post">
    <div class="panel panel-default" style="max-500px">
        <div class="panel-body">
            
             <div class="input-group">
                <span class="input-group-addon">代号:</span>
                <input type="text" class="form-control" placeholder="请输入代号" name="code">
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">姓名:</span>
                <input type="text" class="form-control" placeholder="请输入姓名" name="name">
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">性别:</span>
                &nbsp;&nbsp;
                男<input type="radio" name="sex" value="1" />
                &nbsp;
                女<input type="radio" name="sex" value="0" />
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">民族:</span>
                &nbsp;&nbsp;
                   <select name="nation">
                    <?php
                    $db = new MySQLi("localhost","root","123","mydb");
                    $sql = "select * from nation";
                    $result = $db->query($sql);
                    if($result){
                        $arr = $result->fetch_all();
                        foreach($arr as $v){
                            echo "<option value='{$v[0]}'>{$v[1]}</option>";
                        }
                    }
                    ?>
                </select>
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">生日:</span>
                <input type="text" class="form-control" placeholder="请输入生日" name="birthday">
            </div>
            <br />
            <input class="btn btn-default" type="submit" value="添加数据">
            
        </div>
    </div>
    </form>
    
    </body>
    </html>

    添加处理界面

    <?php
    $code = $_POST["code"];
    $name = $_POST["name"];
    $sex = (int)$_POST["sex"];
    $nation = $_POST["nation"];
    $birthday = $_POST["birthday"];
    
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "insert into info values('{$code}','{$name}',{$sex},'{$nation}','{$birthday}')";
    
    $result = $db->query($sql);
    
    if($result){
        //header("location:tianjia.php");
        echo "<script type='text/javascript'>window.location.href='tianjia.php';</script>";
    }else{
        echo "添加失败!";
    }

    修改界面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    </head>
    
    <body>
    <h1>修改数据</h1>
    <?php
    //取出主键值
    $code = $_GET["code"];
    //读取该条数据
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "select * from info where code='{$code}'";
    $result = $db->query($sql);
    $arr1 = $result->fetch_row();
    ?>
    <form action="./update.php" method="post">
    <div class="panel panel-default" style="max-500px">
        <div class="panel-body">
            
             <div class="input-group">
                <span class="input-group-addon">代号:</span>
                <input type="text" class="form-control" placeholder="请输入代号" readonly="readonly" name="code" value="<?php echo $arr1[0] ?>">
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">姓名:</span>
                <input type="text" class="form-control" placeholder="请输入姓名" name="name" value="<?php echo $arr1[1] ?>">
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">性别:</span>
                &nbsp;&nbsp;
                男<input type="radio" name="sex" value="1" <?php echo $arr1[2]?"checked='checked'":""; ?> />
                &nbsp;
                女<input type="radio" name="sex" value="0" <?php echo $arr1[2]?"":"checked='checked'"; ?> />
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">民族:</span>
                &nbsp;&nbsp;
                   <select name="nation">
                    <?php
                    $sql = "select * from nation";
                    $result = $db->query($sql);
                    if($result){
                        $arr = $result->fetch_all();
                        foreach($arr as $v){
                            if($v[0]==$arr1[3]){
                                echo "<option value='{$v[0]}' selected='selected'>{$v[1]}</option>";
                            }else{
                                echo "<option value='{$v[0]}'>{$v[1]}</option>";
                            }
                        }
                    }
                    ?>
                </select>
            </div>
            <br />
            <div class="input-group">
                <span class="input-group-addon">生日:</span>
                <input type="text" class="form-control" placeholder="请输入生日" name="birthday" value="<?php echo $arr1[4] ?>">
            </div>
            <br />
            <input class="btn btn-default" type="submit" value="修改数据">
            
        </div>
    </div>
    </form>
    
    </body>
    </html>

    修改处理页面

    <?php
    $code = $_POST["code"];
    $name = $_POST["name"];
    $sex = (int)$_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}'";
    
    $result = $db->query($sql);
    if($result){
        header("location:main.php");
    }else{
        echo "修改失败!";
    }

    删除界面

    <?php
    $code = $_GET["code"];
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "delete from info where code='{$code}'";
    $result = $db->query($sql);
    if($result){
        header("location:main.php");
    }else{
        echo "删除失败!";
    }
  • 相关阅读:
    Maximum sum-动态规划
    Ubuntu14下Hadoop开发&lt;1&gt; 基础环境安装
    POJ 3252 Round Numbers 数学题解
    ubuntu环境 rake aborted!
    oracle decode函数用法
    Android多线程研究(1)——线程基础及源码剖析
    2014冬去春来
    Android中的动画详解系列【4】——Activity之间切换动画
    JavaScript你所不知道的困惑(3)
    研发人员技术定级的一些思考
  • 原文地址:https://www.cnblogs.com/Whitehat/p/8456632.html
Copyright © 2011-2022 走看看