search
Homephp教程php手册一个php留言板实例详解

留言板可以说是所有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[&#39;username&#39;]) ? $_REQUEST[&#39;username&#39;] : &#39;&#39;; //姓名
$sex = isset($_REQUEST[&#39;sex&#39;]) ? intval($_REQUEST[&#39;sex&#39;]) : 1; //性别
$msg = isset($_REQUEST[&#39;msg&#39;]) ? $_REQUEST[&#39;msg&#39;] : &#39;&#39;; //留言
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(&#39;$username&#39;,&#39;$sex&#39;,&#39;$msg&#39;)");
} 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 &#39;<td>&#39; . $row[&#39;username&#39;] . &#39;</td>&#39;;
    echo &#39;<td>&#39; . ($row[&#39;sex&#39;] == 1 ? &#39;男&#39; : &#39;女&#39;) . &#39;</td>&#39;;
    echo &#39;<td>&#39; . $row[&#39;msg&#39;] . &#39;</td>&#39;;
}
?>
  </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>


本文地址:

转载随意,但请附上文章地址:-)

Statement
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

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)