zoukankan      html  css  js  c++  java
  • PHP、修改删除

    以下面网页为例。

    主页面

     1 <body>
     2     <div style="height: 50px;"></div>
     3     
     4       <table class="table">
     5         <thead>
     6           <tr>
     7             <th>代号</th>
     8             <th>姓名</th>
     9             <th>英雄类型</th>
    10             <th>性别</th>
    11             <th>种族</th>
    12             <th>你说了算</th>
    13           </tr>
    14         </thead>
    15         <tbody>
    16             
    17     <?php
    18     
    19         $db = new mysqli("localhost","root","","0710");
    20         $sql = "select * from sanguo";
    21         $result = $db->query($sql);
    22         $arr = $result->fetch_all();
    23         foreach($arr as $v){
    24             echo "<tr>
    25             <td>{$v[0]}</td>
    26             <td>{$v[1]}</td>
    27             <td>{$v[2]}</td>
    28             <td>{$v[3]}</td>
    29             <td>{$v[4]}</td>
    30             <td>
    31                 <a href='shanchu1.php?code={$v[0]}'
    32                  onclick="return confirm('are you ready')">
    33                 <button type='button' class='btn btn-danger'>删除</button>
    34                 </a>
    35                 <a href='xiugai.php?code={$v[0]}'
    36                  onclick="return confirm('are you ready')">
    37                  <button type='button' class='btn btn-warning'>修改</button>
    38                  </a>
    39             </td>
    40           </tr>";
    41         }
    42             
    43     ?>
    44     
    45         </tbody>
    46       </table>
    47     
    48     
    49     </body>

    删除处理页面

     1 <?php
     2 $code = $_GET["code"];
     3 $db = new mysqli("localhost","root","","0710");
     4 $sql = "delete from sanguo where code='{$code}'";
     5 if($db->query($sql)){
     6     header("location:shanchu.php");
     7 }else{
     8     echo "error";
     9 }
    10 ?>

    修改页面

     1 <body>
     2         <div style="height:50px"></div>
     3 <?php
     4 $code = $_GET["code"];
     5 $db = new MySQLi("localhost","root","","0710");
     6 $sql = "select * from sanguo where code='{$code}'";
     7 $result = $db->query($sql);
     8 $arr = $result->fetch_row();
     9 ?>
    10         <form action="xiugai1.php" method="post" style="max-650px">
    11             <div class="panel panel-primary">
    12                 <div class="panel-heading">
    13                     <h3 class="panel-title">修改数据</h3>
    14                 </div>
    15                 <div class="panel-body">
    16                     <div class="input-group">
    17                     <span class="input-group-addon" >英雄代号</span>
    18                         <input type="text" class="form-control" placeholder="编码呢?" name="code" value="<?php echo $arr[0] ?>">
    19                     </div>
    20                     <div class="input-group">
    21                     <span class="input-group-addon">英雄姓名</span>
    22                         <input type="text" class="form-control" placeholder="他的名字" name="name" value="<?php echo $arr[1] ?>">
    23                     </div>
    24                     <div class="input-group">
    25                     <span class="input-group-addon">英雄类型</span>
    26                         <input type="text" class="form-control" placeholder="出什么呢?" name="six" value="<?php echo $arr[2] ?>">
    27                     </div>
    28                     <div class="input-group">
    29                     <span class="input-group-addon">英雄性别</span>
    30                         <input type="text" class="form-control" placeholder="男女?" name="zhongzu" value="<?php echo $arr[3] ?>">
    31                     </div>
    32                     <div class="input-group">
    33                     <span class="input-group-addon">英雄种族</span>
    34                         <input type="text" class="form-control" placeholder="what?" name="leixing" value="<?php echo $arr[4] ?>">
    35                     </div>
    36                 </div>
    37                 <button type="submit" class="btn btn-primary queding">修改</button>
    38             </div>
    39             
    40             
    41         </form>        
    42     </body>

    修改处理页面

     1 <?php
     2 $code = $_POST["code"];
     3 $name = $_POST["name"];
     4 $six = $_POST["six"];
     5 $zhongzu = $_POST["zhongzu"];
     6 $leixing = $_POST["leixing"];
     7 
     8 $db = new mysqli("localhost","root","","0710");
     9 
    10 $sql = "update sanguo set name='{$name}',six='{$six}',
    11 zhongzu='{$zhongzu}',leixing='{$leixing}' where code='{$code}'";
    12 
    13 if($db->query($sql)){
    14     header("location:shanchu.php");
    15 }else{
    16     echo "error";
    17 }
    18 ?>
  • 相关阅读:
    字符串函数---atof()函数具体解释及实现(完整版)
    curl的简单使用
    [7] 算法之路
    springMVC3.0(文件上传,@RequestMapping加參数,@SessionAttributes,@ModelAttribute,转发,重定向,数值获取,传參,ajax,拦截器)
    hdu 1754 I Hate It 线段树 点改动
    经典的7种排序算法 原理C++实现
    自己定义View实现水平滚动控件
    centos编译ffmpeg x264
    工作脚本处理文本
    A*寻路算法
  • 原文地址:https://www.cnblogs.com/sunzhenkun/p/7470516.html
Copyright © 2011-2022 走看看