Home Backend Development PHP Tutorial Simple PHP guestbook example code_PHP tutorial

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" />&lt ;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 ;

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'...
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 Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles