Home > php教程 > php手册 > php开发留言板的CRUD(增,删,改,查)操作

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

WBOY
Release: 2016-06-06 20:40:37
Original
1017 people have browsed it

php学习中,以开放一个留言本作为php的入门资料还是不错的。

项目中所需的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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template