• PHP-HTML-MYSQL表格添加删除


    1.展示表格

    <?php
    $daku=mysql_connect("localhost","root","962500");
    if(!$daku){die("error".mysql_error());}
    mysql_select_db("aaaaaa",$daku);
    mysql_query("set names utf8",$daku);
    $xiaoku=mysql_query("select * from qqq " ) or die (mysql_error());
    
    ?>
    
    
    <table align="center" width="600" border="1"> <th>ID</th><th>用户名</th><th>年龄</th><th>日期</th><th>成绩</th><th>操作</th>
    <?php while ($biao=mysql_fetch_array ($xiaoku)){?>
        <tr>
       
       <td><?php echo $biao ['id'];?></td>
       <td><?php echo $biao ['name'];?></td>
     <td><?php echo $biao ['age'];?></td>
       <td><?php echo $biao ['date'];?></td>
       <td><?php echo $biao ['score'];?></td>
       <td><a href="delete.php?id=<?php echo $biao ['id'];?>" onClick="return confirm ('yes?')">删除</a></td>
       </tr>
        <?php }
    ?>
    <tr align="center"><td colspan="6"><a href="add.php">注册</a></td></tr>
    </table>

    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>
    <?php 
    $daku=mysql_connect("localhost","root","962500");
    if(!$daku){die("error".mysql_error());}
    mysql_select_db("aaaaaa",$daku);
    mysql_query("set names utf8",$daku);
    $fid=$_GET['id'];
    $res=mysql_query("delete from qqq where id=$fid");
    if($res){echo "success";
    header("location:test.php");
    }
    else{echo "error";}
    
    ?>
    </body>
    </html>

    3.添加表格

    <?php
    include "open.php";
    if(@$_POST['sub']){
        $name=$_POST['name'];
        
        $date=$_POST['date'];
        $age=$_POST['age'];
        $score=$_POST['score'];
        $sex=$_POST['sex'];
        $res=mysql_query("insert into qqq(name,date,age,score,sex) values ('$name','$date',$age,$score,'$sex')") or die(mysql_error()) ;
        if($res){
            //echo "Success!";
            echo "<script>alert('注册成功');
            location.href='test.php'</script>";    
        }else{
            echo "Error";
        }
    }
    ?>
    
    
    <!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>
    <form action="add.php" method="post">
    <table align="center"  width="300th" border="1" cellpadding="0" cellspacing="0">
    <caption>注册</caption>
    
    <tr> <td>用户名</td>
    <td> <input type="text" name="name"/></td></tr>
    <tr> <td>年龄</td>
    <td> <input type="text" name="age"/></td></tr>
    <tr> <td>日期</td>
    <td> <input type="text" name="date"/></td></tr>
    <tr> <td>成绩</td>
    <td> <input type="text" name="score"/></td></tr>
    <tr> <td>性别</td>
    <td> <input type="text" name="sex"/></td></tr>
    <tr align="center"><td colspan="2"><input type="submit" name="sub" value="注册" /></td></tr></table></form>
    </body>
    </html>

    4.连接数据库代码

    <?php
    $daku=mysql_connect("localhost","root","962500");
    if(!$daku){die("error".mysql_error());}
    mysql_select_db("aaaaaa",$daku);
    mysql_query("set names utf8",$daku);
    $xiaoku=mysql_query("select * from qqq limit 0,5" ) or die (mysql_error());?>
  • 相关阅读:
    数据表的水平拆分
    高性能网站架构
    文本框内容改变触发事件
    树莓派3B(1)- Raspberry Pi 3B 安装系统并联网
    一年经验Java程序员面经小记
    Windows系统安装总结
    树莓派3B(2)- 配置多个wifi,自动寻找可用网络
    Centos7 Apache实现Http访问SVN资源库
    Centos7搭建svn服务
    读《重构 改善既有代码的设计》有感
  • 原文地址:https://www.cnblogs.com/mary-chrisima/p/6992934.html
Copyright © 2020-2023  润新知