留言板可以说是所有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;
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>
本文地址:
转载随意,但请附上文章地址:-)

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

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