Home > php教程 > php手册 > body text

简单的PHP留言本实例代码

WBOY
Release: 2016-06-06 20:33:44
Original
1361 people have browsed it

对于学习php的朋友,开始做个留言板对于php+mysql的操作有个简单的过程。学会了这个基本上php开始入门了。

config.php
代码如下:
$conn = @mysql_connect("localhost","root","") or die("数据库连接出错!");
mysql_select_db("gb",$conn);
mysql_query("set names 'GBK'");
?>

add.php
代码如下:
include("config.php");
if($_POST['submit']){
//在这里的时候,忘记message里还有个字段lastdate没有写,导致插入数据不成功。找了好久才找出错误。
$sql="insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo "成功";
}
?>

用户:

标题:

内容:




view.php
代码如下:
include("config.php");
?>

$sql="select * from message order by id desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
?>
//NND。我在wampserver默认环境下,使用=$row[title]?>这种语法,就是读取不出内容来。非要用这种才可以。郁闷。又是好久才琢磨出来






}
?>
标题: 用户:
内容:


然后还有个数据库的SQL。
代码如下:
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 ;
Related labels:
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 Recommendations
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!