一个php留言板实例详解(附源码下载)
1.在你的PHP的根目录下创建一个名为”msgboard”的文件夹。
在”msgboard”下创建一个“msglist.php”文件
数据表结构大家可直接导入
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5299')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5299>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 文件,包括了留言增加,删除,修改
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2299')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2299>
<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(!empty($username) && !empty($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>
一个php留言板实例下载:http://file.jiaochengji.com/download/2013/06/08/msgboard.rar
您可能感兴趣的文章:
php留言板功能模块有哪些
一个php留言板实例详解(附源码下载)
WordPress常用的函数、方法汇总
挑战最棒的留言本的源码(一)
php xml留言板实例教程一
ajax实现局部刷新页面--留言刷新
php源码去哪下
PHP实现微信模板消息发送给指定用户
jquery源码解析-文章
PHP开发之网页留言板的思路及设计