Simple PHP guestbook example code_PHP tutorial
Jul 21, 2016 pm 03:38 PM
config.php
php
code
copy
Example
of
Simple
config.php
Copy code The code is as follows:
<?php
$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:
<?php
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";
}
?>
<form action="add.php" method="post ">
User:<input type="text" name="user" /><br>
Title:<input type="text" name="title" />< ;br />
Content:<textarea name="content"></textarea><br />
<input type="submit" name="submit" value=" Submit" />
</form>
view.php
Copy code The code is as follows:
<?php
include("config.php");
?>
<table width=500 border="0" align="center" cellpadding= "5" cellspacing="1" bgcolor="#add3ef">
<?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
<tr bgcolor="#eff3ff">
<td>Title: <?php echo $row[title];?> User: <?php echo $row[user];?></td>
</tr>
<tr bgColor="#ffffff">
<td>Content: <?php echo $row[content];?></td>
</tr>
<?php
}
?>
</table>
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 ;
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

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
