建立数据库bbs,
在数据库bbs中建立表message,如下:
CREA TE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
1、(保存为conn.PHP)
$conn = @ mysql_connect("127.0.0.1","root","") or die("数据库链接错误");
mysql_select_db("bbs",$conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
function htmtocode($content) {
$content = str_replace("\n", "
", str_replace(" ", " ", $content));
return$content;
}
//$content=str_replace("'","‘",$content);
//htmlspecialchars();
?>
注释:替换输入内容中输入的回车和空格,写入这个函数后,在list.php中的内容输出语句写为:Echo
function htmtocode($content) {
$content = str_replace("\n", "
", str_replace(" ", " ", $content));
return$content;
2、(保存为add.php)
include("conn.php");
include("head.php");
if($_POST[submit])
{
$sql="insert into message
values('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
if(mysql_query($sql)) {echo"发布成功";}
}
?>
function CheckPost()
{ if (http://www.doczj.com/doc/ff2c6d4a767f5acfa1c7cd3a.htmler.value=="")
{ alert("请填写用户名");http://www.doczj.com/doc/ff2c6d4a767f5acfa1c7cd3a.htmler.focus();return false;}
if (myform.title.value.length<5)//这里的5个字符是5个汉字或者是5个字母。