zoukankan      html  css  js  c++  java
  • 补完 简单的增删

    目的是为了在页面现实数据并且实现增加和删除数据的功能

    1.首先需要布局表格来放数据库里面的内容

    例:

    <table width="100%" border="1" cellpadding="0" cellspacing="0" >
        <tr>
            <td>姓名</td>
            <td>身份证号</td>
            <td>电话</td>
            <td>房间类型</td>
            <td>定金</td>
            <td>操作</td>
        </tr>

    2.查询数据库病显示

    <?php
        
            $db = new MySQLi("localhost","root","123","酒店");
            $sql = "select * from yuding";
            
            $result = $db->query($sql);
            
            while($attr = $result->fetch_row())
        {
            echo "<tr><td>{$attr[1]}</td><td>{$attr[2]}</td><td>{$attr[3]}</td><td>{$attr[4]}</td><td>{$attr[5]}</td><td>
            
            
            </td></tr>";
        }    
        
        
        
        
        
        ?>

    3.添加页面

    <?php
    
    $name = $_POST["name"];
    $id = $_POST["id"];
    $tel = $_POST["tel"];
    $type = $_POST["type"];
    $dmoney = $_POST["dmoney"]; 
    if(!empty($name) && !empty($id) && !empty($tel) && !empty($type) && !empty($dmoney))//这句是为了保证文本框里面都有内容,;类似非空验证
    {
                $db = new MySQLi("localhost","root","123","酒店");
            
            $sql = "insert into yuding values('','{$name}','{$id}','{$tel}','{$type}','{$dmoney}')";
            
            
            $x = $db->Query($sql);
            if($x)
            {
                header("location:yuding.php");
            }
            else
            {
                echo"添加失败=-=";
            }
    }else
    {
        echo "内容不能有空";
        header("location:yuding.php");
        }

    4.删除以及删除页面

    在上面2.的代码里面添加

    <td>

    <a href='ydshanchu.php?code={$attr[0]}' onclick="return confirm('确定删除么')">
    删除
    </a>
    </td>, 

    <?php
    $code = $_GET["code"];
    $db = new MySQLi("localhost","root","123","酒店");
    
    $sql = "delete from yuding where ids='{$code}'";
    
    $x = $db->query($sql);
    if($x)
    {
        header("location:yuding.php");
    }
    else
    {
        echo "删除失败";
    }
  • 相关阅读:
    CF1174D Ehab and the Expected XOR Problem
    CF1083B The Fair Nut and Strings
    CF1088D Ehab and another another xor problem
    CF1168A Increasing by Modulo
    CF1166C A Tale of Two Lands
    CF1142A The Beatles
    CF1105D Kilani and the Game
    【uva11248】网络扩容
    【sam复习】用sam实现后缀排序
    【Educational Codeforces Round 19】
  • 原文地址:https://www.cnblogs.com/xiaoming-6/p/6372956.html
Copyright © 2011-2022 走看看