Home > Backend Development > PHP Tutorial > php开发留言板的CRUD(增,删,改,查)操作_php实例

php开发留言板的CRUD(增,删,改,查)操作_php实例

WBOY
Release: 2016-06-07 17:25:33
Original
1478 people have browsed it

项目结构:

添加页面:                                说明:这里只注重操作,对界面的美工没有下工夫,希望大家理解......

列表页面:

修改页面:

项目中所需的sql:

复制代码 代码如下:

create database form;

use form;

CREATE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;


conn.php
复制代码 代码如下:

$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("form", $conn);
mysql_query("set names 'gbk'");
?>

add.php
复制代码 代码如下:

include 'conn.php';
if($_POST['submit']){
$sql="INSERT INTO message(id,user,title,content,lastdate) VALUES (NULL, '$_POST[user]', '$_POST[title]', '$_POST[content]', now())";
mysql_query($sql);

//页面跳转,实现方式为javascript
$url = "list.php";
echo "";
}
?>


用户:

标题:

内容:



list.php
复制代码 代码如下:

include 'conn.php';
?>
echo "";
?>

$sql="select * from message order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>











标题:=$row[title]?> 用户:=$row[user] ?>
编辑  |  删除
内容:=$row[content]?>
发表日期:=$row[lastdate]?>


delete.php
复制代码 代码如下:

include 'conn.php';
$id = $_GET['id'];
$query="delete from message where id=".$id;
mysql_query($query);
?>
//页面跳转,实现方式为javascript
$url = "list.php";
echo "";
?>

preEdit.php
复制代码 代码如下:

include 'conn.php';
$id=$_GET[id];
$query="SELECT * FROM message WHERE id =".$id;
$result=mysql_query($query);
while ($rs=mysql_fetch_array($result)){
?>


用户:

标题:

内容:





postEdit.php
复制代码 代码如下:

include 'conn.php';
$query="update message set user='$_POST[user]',title='$_POST[title]',content='$_POST[content]' where id='$_POST[id]'";
mysql_query($query);
?>
//页面跳转,实现方式为javascript
$url = "list.php";
echo "";
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template