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";
}
?>
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 =$row[title]?>, 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 ;
http://www.bkjia.com/PHPjc/321804.htmlwww.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'...