练习题内容:

一、查看新闻页面-----主页面:

<!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>id</td>
<td>title</td>
<td>author</td>
<td>source</td>
<td>content</td>
<td>date</td>
<td>update</td>
<td>delete</td>
</tr>
<?php
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("连接失败!");
$sql="select * from news";
$result=$db->query($sql);
$arr=$result->fetch_all();
foreach ($arr as $v)
{
echo "<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td><a href='Update.php?newsid={$v[0]}'>update</a></td>
<td><a href='Delete.php?newsid={$v[0]}'>delete</a></td> </tr>";
} ?>
</table>
<br>
<br />
<div class="xw"><a href="xinwen.php">发布新闻</a></div> </body>
</html>

  

二、发布新闻页面-----添加内容:

<!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>
<style>
.xw
{ margin-top:10px;
margin-left:400px;
border:thick;
}
.a
{
float:left; } </style> </head> <body>
<h1><center>发布新闻</center></h1> <form action="AddChu.php" method="post">
<div class="xw">标题:<input type="text" name="title" style="width:400px"></div>
<div class="xw">作者:<input type="text" name="author"></div>
<div class="xw">来源:<input type="text" name="source"></div>
<div class="xw">内容:
<textarea rows="10" cols="80" name="content"></textarea></div> <div class="a"><input type="submit" value="提交" style="margin-left:600px;"></div>
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;"></a></div> </form> </body>
</html>

  

提交内容后的处理:

<?php
$newsid=$_POST["newsid"];
$title=$_POST["title"];
$author=$_POST["author"];
$source=$_POST["source"];
$content=$_POST["content"];
$time=date("Y-m-d",time()); $db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("联系失败!");
$sql="insert into news values('{$newsid}','{$title}','{$author}','{$source}','{$content}','{$time}')";
$result=$db->query($sql);
if($result)
{
header ("location:xinwen.php");
}
else
{
echo "添加新闻失败!";
}

  

三、删除内容处理:

<?php
$newsid=$_GET["newsid"];
$db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("连接失败!");
$sql="delete from news where newsid='{$newsid}'";
$result=$db->query($sql);
if($result)
{
header ("location:ChaKan.php");
}
else
{
echo "删除数据失败";
}
?>

  

四、修改新闻页面----修改新闻内容后提交查看:

<!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>
<style>
.xw
{ margin-top:10px;
margin-left:400px;
border:thick;
} .a
{
float:left; } </style>
</head> <body>
<h1><center>修改新闻</center></h1>
<?php
$newsid = $_GET["newsid"];
$db = new MySQLi("localhost","root","","mydb");
$sinfo = "select * from news where newsid='{$newsid}'";
$r = $db->query($sinfo);
$arr = $r->fetch_row(); //这个人的所有信息
?> <form action="UpdateChu.php" method="post">
<div class="xw"><input type="hidden" name="newsid" value="<?php echo $arr[0] ?>"></div>
<div class="xw">标题:<input type="text" name="title" style="width:400px" value="<?php echo $arr[1] ?>"></div>
<div class="xw">作者:<input type="text" name="author" value="<?php echo $arr[2] ?>"></div>
<div class="xw">来源:<input type="text" name="source" value="<?php echo $arr[3] ?>"></div>
<div class="xw">内容:
<textarea rows="10" cols="80" name="content"><?php echo $arr[4] ?></textarea></div> <div class="a"><input type="submit" value="修改" style="margin-left:600px;"></div>
<div class="a"><a href="ChaKan.php"><input type="button" value="查看" style="margin-left:6px;"></a></div> </form> </body>
</html>

  

提交修改内容后进行处理:

<?php
$newsid=$_POST["newsid"];
$title=$_POST["title"];
$author=$_POST["author"];
$source=$_POST["source"];
$content=$_POST["content"];
$time=date("Y-m-d",time()); $db=new MySQLi("localhost","root","","mydb");
!mysqli_connect_error() or die("联系失败!");
$sql="update news set title='{$title}',author='{$author}',source='{$source}',content='{$content}',time='{$time}' where newsid='{$newsid}'";
$result=$db->query($sql);
if($result)
{
header ("location:Update.php");
}
else
{
echo "修改数据失败!";
}

php 之 数据访问 增删改查练习题的更多相关文章

  1. php 之 数据访问 增删改查

    一.建立主页面: <title>主页面</title> </head> <body> <h1>主页面</h1> <tabl ...

  2. django学习-12.访问不同url/接口地址实现对指定数据的增删改查功能

    1.前言 通过前面博客[django学习-10.django连接mysql数据库和创建数据表]里的操作,我们已经成功在数据库[hongjingsheng_project]里创建了一张数据表[hello ...

  3. dbutils中实现数据的增删改查的方法,反射常用的方法,绝对路径的写法(杂记)

    jsp的三个指令为:page,include,taglib... 建立一个jsp文件,建立起绝对路径,使用时,其他jsp文件导入即可 导入方法:<%@ include file="/c ...

  4. 数据的增删改查(三层)<!--待补充-->

    进行数据操作必然少了对数据的增删改查,用代码生成器生成的代码不是那么满意!方便在今后使用,这里就主要写“数据访问层(Dal)” 既然这里提到三层架构:有必要将三层内容在这里详细介绍一下(待补充) 注: ...

  5. Node.js + MySQL 实现数据的增删改查

    通过完成一个 todo 应用展示 Node.js + MySQL 增删改查的功能.这里后台使用 Koa 及其相应的一些中间件作为 server 提供服务. 初始化项目 $ mkdir node-cru ...

  6. Django框架之第二篇--app注册、静态文件配置、form表单提交、pycharm连接数据库、django使用mysql数据库、表字段的增删改查、表数据的增删改查

    本节知识点大致为:静态文件配置.form表单提交数据后端如何获取.request方法.pycharm连接数据库,django使用mysql数据库.表字段的增删改查.表数据的增删改查 一.创建app,创 ...

  7. Mybatis框架基于注解的方式,实对数据现增删改查

    编写Mybatis代码,与spring不一样,不需要导入插件,只需导入架包即可: 在lib下 导入mybatis架包:mybatis-3.1.1.jarmysql驱动架包:mysql-connecto ...

  8. MVC模式:实现数据库中数据的增删改查功能

    *.数据库连接池c3p0,连接mysql数据库: *.Jquery使用,删除时跳出框,确定是否要删除: *.使用EL和JSTL,简化在jsp页面中插入的java语言 1.连接数据库 (1)导入连接数据 ...

  9. Hibernate3回顾-5-简单介绍Hibernate session对数据的增删改查

    5. Hibernate对数据的增删改查 5.1Hibernate加载数据 两种:get().load() 一. Session.get(Class arg0, Serializable arg1)方 ...

随机推荐

  1. python 3.5 购物小程序

    #!/usr/bin/env python #encoding: utf-8 import time import os nowtime = time.strftime('%Y-%m-%d %H:%M ...

  2. 『局域网安全』利用ARP欺骗劫持Cookie

    0x 00 ARP欺骗说明 欺骗原理相关内容就不多叙述了,百度一大堆 实施ARP欺骗在Windows下,Linux下都相关工具 由于在Linux下可以开启ip_forward功能,个人认为Linux下 ...

  3. cf C. Maze

    http://codeforces.com/problemset/problem/378/C #include <cstdio> #include <cstring> #inc ...

  4. QT的文本加密方法(寒山居士)

    http://blog.csdn.net/esonpo/article/details/12746315http://blog.csdn.net/esonpo/article/details/1174 ...

  5. SignalR 的跨域支持

    How to establish a cross-domain connection Typically if the browser loads a page from http://contoso ...

  6. Visual Studio新建的源文件的默认编码

    原来VS新建的源文件默认的编码是根据系统locale选择的.我的是国标2312.我草.可坑死我了.一直不知道. 当时主要是需要用doxygen生成html文档,它默认的输入文件的格式是UTF-8,是不 ...

  7. linux开源论坛

    开源资源: 开源http://oss.org.cn/?action-news http://www.lupaworld.com/proj.php http://www.10pig.cn/linux/o ...

  8. 动态共享库(so)开发精悍教程

    动态共享库(so)开发精悍教程 翻译并根据实际情况进行了小小修改,仅关注Linux下动态共享库(Dynamic shared library .so)的开发. 1 简单的so实例 源文件 //test ...

  9. iOS 9之分屏多任务(Split View)

    金田(github 示例源码) 多任务(multitasking)算是iOS9中最引人瞩目的核心新特性了,之前越狱版用户就用过类似的插件,微软的 苏菲 (Windows Surface)系列也有分屏多 ...

  10. js原型继承深入

    js采用原型继承来实现类的派生,但是原型链再深入点,我们又知道多少呢,现在不妨往下看: 先来一个原型继承: var M1 = function() { this.param = "m1's ...