Home > Backend Development > PHP Tutorial > PHP message board creation tutorial_PHP tutorial

PHP message board creation tutorial_PHP tutorial

WBOY
Release: 2016-07-13 17:15:07
Original
925 people have browsed it

This article provides PHP beginners with an article to share the entire process from the creation of the database to the final reading and writing of the message board with friends. If you need to know more, you can refer to it.

Create a data table

The code is as follows Copy code
 代码如下 复制代码

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 ;

CREATE TABLE `message` (

`id` tinyint(1) NOT NULL auto_increment,

`user` varchar(25) NOT NULL,

`title` varchar(50) NOT NULL,
 代码如下 复制代码

$conn = mysql_connect("localhost", "root", "") or die("数据库链接错误");

mysql_select_db("test", $conn);

mysql_query("set names ‘GBK'"); //使用GBK中文编码;

?>

`content` tinytext NOT NULL,
`lastdate` date NOT NULL,

PRIMARY KEY (`id`)
 代码如下 复制代码

include("conn.php");

if($_POST['submit']){

$sql="insert into message (id,user,title,content,lastdate) values (",'$_POST[user]‘,'$_POST[biaoti]‘,'$_POST[content]‘,now())";

mysql_query($sql);

echo "成功发表!";

}

?>


发表留言框

用户:


标题:



) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;


Database connection file
 代码如下 复制代码

include ("conn.php");

?>

$sql="select * from message ";

$query=mysql_query($sql);

while($row=mysql_fetch_array($query)){ ?>

标题: 用户:
发表内容:

The code for database connection is relatively fixed. First create a new conn.php file and enter the following code:
The code is as follows Copy code
<🎜>$conn = mysql_connect("localhost", "root", "") or die("Database link error");<🎜> <🎜>mysql_select_db("test", $conn);<🎜> <🎜>mysql_query("set names ‘GBK'"); //Use GBK Chinese encoding;<🎜> <🎜>?>
Write a message page file Create a new file add.php and enter the following code:
The code is as follows Copy code
<🎜>include("conn.php");<🎜> <🎜>if($_POST['submit']){<🎜> <🎜>$sql="insert into message (id,user,title,content,lastdate) values ​​(",'$_POST[user]','$_POST[biaoti]','$_POST[content]',now ())";<🎜> <🎜>mysql_query($sql);<🎜> <🎜>echo "Published successfully!";<🎜> <🎜>}<🎜> <🎜>?>

Post a message box

User:
Title:

Write message list file Create a new file list.php and enter the following code:
The code is as follows Copy code
<🎜>include ("conn.php");<🎜> <🎜>?> <🎜>$sql="select * from message ";<🎜> <🎜>$query=mysql_query($sql);<🎜> <🎜>while($row=mysql_fetch_array($query)){ ?>
Title: User:
Post content:

Note, This is just an introductory PHP tutorial. If you want to use it on the Internet, please do some security and SQL injection filtering, otherwise it will be very unsafe.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628885.htmlTechArticleThis article provides PHP beginners with an article to share the entire process from the creation of the database to the final reading and writing of the message board. To all my friends, please refer to it if you need to know more. Create a data table...
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