PHP entry message board program implementation code_PHP tutorial

WBOY
Release: 2016-07-13 16:59:49
Original
1146 people have browsed it

The message board program needs to be implemented by php + database. This tutorial mainly talks about the implementation process of the php mysql message system, including adding, modifying, deleting and editing work. It is a good material for beginners of php.

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:

The sql file of the message board can be directly imported into mysql

 代码如下 复制代码
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 database connection file

The code is as follows Copy code
$conn = @ mysql_connect("localhost", "root", "") or die("Database link error");
代码如下 复制代码
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("form", $conn);
mysql_query("set names 'gbk'");
?>
mysql_select_db("form", $conn);

mysql_query("set names 'gbk'");
?>

 代码如下 复制代码

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


 用户:

标题:

内容:

add.php saves the message information submitted by the user to the database
The code is as follows Copy code
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 ""; 12 } ?>
User:
Title:
Content:

list.php 以列表形式输出留言

 代码如下 复制代码
 代码如下 复制代码

include 'conn.php';
?>
echo "

";
?>
 
  $sql="select * from message order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>
 
  
  
 
  
  
  
  
  
  
  
 
标题: 用户:
内容:
发表日期:

include 'conn.php';
?>
echo "";
?>
 
  $sql="select * from message order by id";
 $query=mysql_query($sql);
 while ($row=mysql_fetch_array($query)){
 ?>
 
  
  
 
  
  
  
  
  
  
  
 
标题: 用户:
编辑  |  删除
内容:
发表日期:

delete.php 删除留言,根据用户提交的数据,我们以获取留言内容的ID进行删除操作
 代码如下 复制代码
  $id = $_GET['id'];
$query="delete from message where id=".$id;
mysql_query($query); ?>
echo ""; ?>

PreEdit.php editing is to use update to update the data resubmitted by the user and replace the previous record with id as the unique identifier


$id=$_GET[id]; $query="SELECT * FROM message WHERE id=".$id;
The code is as follows
 代码如下 复制代码

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

Copy code

include 'conn.php';

$result=mysql_query($query);

while ($rs=mysql_fetch_array($result)){

?>

User:
Title:
Content:
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);

?> //Page jump, implemented by javascript $url = "list.php"; <🎜> echo ""; ?> Summary This is a complete message board system. As long as you save it as a file according to the above tips, you can effectively implement the message function. The message board mainly includes data reading, paging and data deletion and editing. We divide it into The three statements of sql delete, update, and insert are relatively basic knowledge. http://www.bkjia.com/PHPjc/631287.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631287.htmlTechArticleThe message board program needs to be implemented by php + database. This tutorial mainly talks about the implementation of the php mysql message system. The process, including addition, modification, deletion and editing work, is suitable for beginners of PHP...
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