zoukankan      html  css  js  c++  java
  • 数据访问之增加、删除


    <!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> </head> <body> <h1>主页面</h1> //把Info表查出来,用一个表格显示 <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td>代号</td> <td>姓名</td> <td>性别</td> <td>民族</td> <td>生日</td> <td>操作</td> </tr> <?php $db=new MySQLi("localhost","root","","mydb"); !mysqli_connect_error() or die ("连接失败"); $sql="select * from Info"; $result=$db->query($sql); $arr=$result->fetch_all(); foreach($arr as $v) { $sex = $v[2]?'男':'女'; //处理民族名称 $sqln = "select Name from Nation where Code='{$v[3]}'"; $r = $db->query($sqln); $attr = $r->fetch_assoc(); echo "<tr> <td>{$v[0]}</td> <td>{$v[1]}</td> <td>{$sex}</td> <td>{$attr['Name']}</td> <td>{$v[4]}</td> <td><a href='Delete.php?code={$v[0]}'>删除</a></td> </tr>"; } ?> </table> <div><a href="Add.php">添加数据</a></div> </body> </html>

    <body>
    <h1>添加数据</h1>
    <form action="AddChuLi.php" method="post">
    <div>代号:<input type="text" name="code"/></div><br />
    <div>姓名:<input type="text" name="name" /></div><br />
    <div>性别:
            <input type="radio" value="男" name="sex"/><input type="radio" value="女" name="sex"/></div><br />
    <div>民族:
              <select name="nation">
              <?php
              $db=new MySQLi("localhost","root","","mydb");
              $sql="select * from Nation";
              $result=$db->query($sql);
              $attr=$result->fetch_all();
              foreach($attr as $v )
              {
                  echo "<option value='{$v[0]}'>{$v[1]}</option>";
              }         
              ?>
              </select></div><br />
    
    <div>生日:<input type="text" name="birthday" /></div><br />
    <div><input type="submit" value="添加数据" /></div>
    <div><a href="main.php">主页</a></div>
    
    
    </form>
    </body>

    <?php
    $code = $_POST["code"];
    $name = $_POST["name"];
    $sex = $_POST["sex"];
    $s = 1;
    if($sex == "女")
    {
        $s = 0;
    }
    $nation = $_POST["nation"];
    $birthday = $_POST["birthday"];
    
    $db = new MySQLi("localhost","root","","mydb");
    $sql = "insert into Info values('{$code}','{$name}',{$s},'{$nation}','{$birthday}')";
    //var_dump($sql);
    $result = $db->query($sql);
    
    if($result)
    {
        header("location:Add.php");//跳转到Add.php
    }
    else
    {
        echo "添加失败!";
    }
    <?php
    $code=$_GET["code"];
    $db=new MySQLi("localhost","root","","mydb");
    !mysqli_connect_error() or die ("连接失败");
    $sql="delete from Info where code='{$code}'";
    $result=$db->query($sql);
    if($result)
    {
        echo header("location:main.php");
    }
    else
    {
        echo"删除失败";
    }
  • 相关阅读:
    Oracle连接与会话
    数据库物理备份与恢复系列之——数据库手动热备份和恢复
    RHCS 6.5 由于resource-agents-3.9.2-40.el6版本过低导致rgmanager[61164]: [fs] umount failed
    ORA-20011 ORA-29913 and ORA-29400 with Associated KUP-XXXXX Errors from DBMS_STATS.GATHER_STATS_JOB(Doc ID 1274653.1)
    initrd image比lvm.conf文件舊導致RHCS切換服務unmount failed,reboot
    Oracle监听的静态注册和动态注册
    Linux下安裝Oracle database內核參數設置
    kkjcre1p: unable to spawn jobq slave process, slot 0, error 1089(Linux x86_64)补丁
    NHibernate系列
    Oracle设置主键自增长
  • 原文地址:https://www.cnblogs.com/nannan-0305/p/5483491.html
Copyright © 2011-2022 走看看