zoukankan      html  css  js  c++  java
  • PHP数据库页面增删查

    1.用户操作页面

    <!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>
    <table width="100%" border="1" 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","mydb");
        //写SQL语句
        $sql = "select * from fruit";
        
        //执行
        $result = $db->query($sql);
        
        //取数据
        /*$attr = $result->fetch_all();
        
        foreach($attr as $v)
        {
            echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td></tr>";
        }*/
        
        while($attr = $result->fetch_row())
        {
            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]}' onclick="return confirm('确定删除么')">
            删除
            </a>
            </td></tr>";
        }
        
        
        ?> 
    
    </table>
    <a href="add.php">添加数据</a>
    </body>
    <script type="text/javascript">
    
    </script>
    </html>

    2.添加数据页面

    <!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>
    <form action="addchuli.php" method="post">
    <div>代号:<input type="text" name="ids" /></div>
    <div>名称:<input type="text" name="name" /></div>
    <div>价格:<input type="text" name="price" /></div>
    <div>产地:<input type="text" name="chandi" /></div>
    <div>库存:<input type="text" name="numbers" /></div>
    <div><input type="submit" value="添加" /></div>
    </form>
    </body>
    </html>

    3.删除处理页面

    <?php
    $code = $_GET["code"];
    
    //造连接对象
    $db = new MySQLi("localhost","root","123","mydb");
    
    //写SQL语句
    $sql = "delete from fruit where ids='{$code}'";
    
    //执行
    $r = $db->query($sql);
    
    if($r)
    {
        header("location:main.php");
    }
    else
    {
        echo "删除失败!";
    }

    4.添加处理页面

    <?php
    $ids = $_POST["ids"];
    $name = $_POST["name"];
    $price = $_POST["price"];
    $chandi = $_POST["chandi"];
    $numbers = $_POST["numbers"];
    
    //造连接对象
    $db = new MySQLi("localhost","root","123","mydb");
    
    //写SQL语句
    $sql = "insert into fruit values('{$ids}','{$name}',{$price},'{$chandi}',{$numbers},'')";
    
    //执行
    $r = $db->query($sql);
    
    if($r)
    {
        header("location:main.php");
    }
    else
    {
        echo "添加失败!";
    }
  • 相关阅读:
    document.compatMode的CSS1compat
    js自运行函数
    Sublime Text 3 入门(插件控制台安装)
    javascript 面向对象技术
    jQuery ui 中文日历
    js给数字加三位一逗号间隔的两种方法(面试题)
    android eclipse集成环境
    中科红旗倒下,谁来挑战windows
    在网站制作中随时可用的10个 HTML5 代码片段
    IE6/IE7中li底部4px的Bug
  • 原文地址:https://www.cnblogs.com/chaochao00o/p/6197009.html
Copyright © 2011-2022 走看看