background image

PHP 实现留言版

开发环境:Ubuntu11.10 ide:Netbeans 

文件结构:

conn.php:负责管理数据库链接;

list.php:显示留言页面;

head.php:头部链接;

add.php:添加留言页;

代码:

//conn.php

<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$db_host='localhost';
$db_user='root';
$db_pass='1';
$db_name='bbs';
 $conn=@mysql_connect($db_host,$db_user,$db_pass) or die("error");
 mysql_select_db("bbs",$conn);
 mysql_query("set names 'utf8'");
 //修正添加空格与换行
 function htmtocode($content) {
$content = str_replace("\n", "<br>", str_replace(" ", " ", $content));
return $content;
}
?>

//list.php

<?php
include ("conn.php")
?>
<table   width=500   border="0"   align="center"   cellpadding="5"   cellspacing="1" 
bgcolor="#add3ef">
 <?
 $sql="select * from message ";