Home > Backend Development > PHP Tutorial > Simple PHP guestbook example code_PHP tutorial

Simple PHP guestbook example code_PHP tutorial

WBOY
Release: 2016-07-21 15:38:06
Original
826 people have browsed it

config.php

Copy code The code is as follows:

$conn = @mysql_connect("localhost","root","") or die("Database connection error!");
mysql_select_db("gb",$conn);
mysql_query("set names 'GBK' ");
?>

add.php
Copy code The code is as follows:

include("config.php");
if($_POST['submit']){
//While here, forget There is also a field last in the message that has not been written, causing data insertion to fail. It took me a long time to find the error.
$sql="insert into message (id,user,title,content,lastdate) values ​​('','$_POST[user]','$_POST[title]','$_POST[content]', now())";
mysql_query($sql);
echo "Success";
}
?>

User:

Title:< ;br />
Content:




view.php
Copy code The code is as follows:

include("config.php");
?>

$sql="select * from message order by id desc";
$query=mysql_query($sql );
while($row=mysql_fetch_array($query)){
?>
//NND. In the default environment of wampserver, I use the syntax , but the content cannot be read. This is the only way to use it. depressed. It took me a long time to figure it out






}
?>
Title: User:
Content:


Then there is also SQL for the database.
Copy code The code is as follows:

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 ;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321804.htmlTechArticleconfig.php Copy the code as follows: ?php $conn = @mysql_connect("localhost","root", "") or die("Database connection error!"); mysql_select_db("gb",$conn); mysql_query("set names 'GBK'...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template