zoukankan      html  css  js  c++  java
  • 页面化操作数据库

    首先默认选择库test1,01.php中然后用show tables;查询出所有的表,然后用循环依次输出所有的表名,和操作超链接,超链接上对应有该表的信息传到02.php,02.php中,根据接收到的参数,查询到该表,然后用desc 表名,结果循环输出表字段名,再查询出所有字段循环输出对应的值,后面有操作超链接,存有该行数据的信息,传到03.php.03.php可以更改

    01.php

    <?php
    $conn=mysql_connect("localhost","root","111111");
    mysql_query("set names utf8",$conn);//设置编码
    mysql_query("use test1");//选库
    $sql="show tables";
    $rs=mysql_query($sql,$conn);
    ?>
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>列出所有表</title>
    </head>
    <body>
        <table border=1 width=50%>
            <p>所有的表</p>
            <tr>
                <td>表名</td>
                <td>操作</td>
            </tr>
            <?php
                while($row=mysql_fetch_assoc($rs)){
                    echo "<tr>";
                    echo "<td>",$row["Tables_in_test1"],"</td>";
                    echo "<td>","<a href=02.php?table=".$row["Tables_in_test1"].">编辑</a></td>";
                    echo "</tr>";
                }
            ?>
        </table>
    </body>
    </html>
    

     02.php

    <?php
    $conn=mysql_connect("localhost","root","111111");
    mysql_query("set names utf8",$conn);//设置编码
    mysql_query("use test1");//选库
    $table=$_GET['table'];//接收数据
    addslashes($table);
    $sql="select * from ".$table;
    $rs=mysql_query($sql,$conn);
    $sql="desc ".$table;
    $ziduan=mysql_query($sql,$conn);
    ?>
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>表中所有的数据</title>
    </head>
    <body>
    <table border=1 width="50%">
        <?php
            $i=0;//记录多少字段
            echo "<tr>";
            while($row=mysql_fetch_row($ziduan)){
                echo "<td>",$row[0],"</td>";
                $i++;
            }
            echo "<td>操作</td>";
            echo "</tr>";
            while($row=mysql_fetch_row($rs)){
                echo "<tr>";
                for($a=0;$a<$i;$a++){
                    echo "<td>",$row[$a],"</td>";
                }
                echo "<td><a href=03.php?id=".$row[0].">编辑</a></td>";
                echo "</tr>";
            }
    
        ?>
    </table>
        
    </body>
    </html>
    

     03.php

    待定

  • 相关阅读:
    大前端完整学习路线(详解)
    浅谈攻击Web应用常见的技术手段
    浅谈XSS跨站脚本攻击
    利用SQL注入漏洞登录后台
    1、MyBatis框架底层初涉
    1、用静态工厂方法代替构造器
    日志管理-log4j与slf4j的使用
    Java的值类型和引用类型
    自动任务调度
    2、Hibernate持久化编写
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4733145.html
Copyright © 2011-2022 走看看