CRUD (add, delete, modify, check) operations for php message board development_PHP tutorial

WBOY
Release: 2016-07-21 15:18:59
Original
935 people have browsed it

Project structure:

Add page: Explanation: Only pay attention to the operation here, and there is no time for the artist of the interface. I hope everyone understands ...

List page:

Modify page:

SQL required in the project:

Copy code The code is as follows:
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

Copy code The code is as follows:
$conn = @ mysql_connect("localhost", "root", "") or die("Database link error");
mysql_select_db("form", $conn);
mysql_query("set names 'gbk'");
?>

add.php

Copy code The code is as follows:
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);

//Page jump, implemented by javascript
$url = "list.php";
echo "";
}
?>
< ;script type="text/javascript">
function checkPost(){

if(addForm.user.value==""){
alert("Please enter username") ;
addForm.user.focus();
return false;
}
if(addForm.title.value.length<5){
alert("The title cannot be less than 5 characters");
addForm.title.focus();
return false;
}
}


User:

Title:

Content:



list .php

Copy code The code is as follows:

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

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











标题: 用户:
编辑  |  删除
内容:
发表日期:


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 "";
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325343.htmlTechArticle项目结构: 添加页面: 说明:这里只注重操作,对界面的美工没有下工夫,希望大家理解...... 列表页面: 修改页面: 项目中所需的sql:...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!