一个php留言板实例详解
message
留言板可以说是所有php入门者都会练习的一个小不上的WEB应用程序了,下面我把我写的一个php留言板实例分享给各位同学,有需要了解的同学可进入参考参考.
1.在你的PHP的根目录下创建一个名为"msgboard"的文件夹.在"msgboard"下创建一个"msglist.php"文件,数据表结构大家可直接导入。
实例代码如下:
CREATE TABLE `msgboard` ( `id` int(10) NOT NULL AUTO_INCREMENT, `username` varchar(50) CHARACTER SET latin1 NOT NULL, `sex` tinyint(1) NOT NULL DEFAULT '1', `msg` text CHARACTER SET latin1 NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Copy after login
msglist.php 文件,包括了留言增加,删除,修改
实例代码如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>我的留言板</title> </head> <body> <?php $username = isset($_REQUEST['username']) ? $_REQUEST['username'] : ''; //姓名 $sex = isset($_REQUEST['sex']) ? intval($_REQUEST['sex']) : 1; //性别 $msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : ''; //留言 mysql_connect("127.0.0.1", "root", "lzy"); //链接 mysql_select_db("test"); //选择数据库 if (!emptyempty($username) && !emptyempty($msg)) { mysql_query("INSERT INTO msgboard(username,sex,msg) VALUES('$username','$sex','$msg')"); } else { echo "输入不正确<br/>"; } $source = mysql_query("SELECT * FROM msgboard ORDER BY id DESC"); $result = array(); ?> <table border="1" width="1000"> <tr align="center"> <td width="10%">姓名</td> <td width="10%">性别</td> <td width="80%">留言内容</td> </tr> <tr> <?php while ($row = mysql_fetch_array($source)) { echo '<td>' . $row['username'] . '</td>'; echo '<td>' . ($row['sex'] == 1 ? '男' : '女') . '</td>'; echo '<td>' . $row['msg'] . '</td>'; } ?> </tr> </table><p/> <form action="msglist.php" method="POST"> <table width="1000" align="left"> <tr> <td width="100%"> 姓名:<input type="text" name="username" value=""/> </td> </tr> <tr> <td width="100%"> 性别:男<input type="radio" name="sex" value="1" checked="checked" /> 女<input type="radio" name="sex" value="0" /> </td> </tr> <tr> <td width="100%"> 请留言:<br/><textarea name="msg" rows="5" cols="100"></textarea> </td> </tr> <tr> <td width="100%"> <input type="submit" value="提 交" /> </td> </tr> </table> </form> </body> </html>
Copy after login
本文地址:
转载随意,但请附上文章地址:-)
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 AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5055523 fails to install in Windows 11?
4 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
4 weeks ago
By DDD
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD

Hot Tools

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
Java Tutorial
1664
14


CakePHP Tutorial
1422
52


Laravel Tutorial
1316
25


PHP Tutorial
1267
29


C# Tutorial
1239
24

