用php写一个最简易的留言板代码讲解
1、数据库链接:<?php/** PHP100Job v1.0* Programmer : Msn/QQ haowubai@hotmail.com (925939)* www.php100.com Develop a project PHP - MySQL - Apache* Window 2003 - Preferences - PHPeclipse - PHP - Code Templates*/header("Content-type: text/html; charset=utf-8");//php页面编码$conn = @ mysql_connect("localhost", "root", "123456") or die("数据库链接失败");mysql_select_db("ceshi", $conn);mysql_query("set names 'utf8'");error_reporting(E_ALL^E_NOTICE^E_WARNING); //关闭报错;function htmtocode($content) { $content = str_replace("\n", "<br>", str_replace(" ", " ", $content)); return $content;}?>

3、插入语句:<?php/** PHP100Job v1.0* Programmer : Msn/QQ haowubai@hotmail.com (925939)* www.php100.com Develop a project PHP - MySQL - Apache* Window 2003 - Preferences - PHPeclipse - PHP - Code Templates*/header("Content-type: text/html; charset=utf-8");//php页面编码include("conn.php");if(isset($_POST['submit'])){ $sql="insert into message (id,user,title,content,lastdate) " . "values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; mysql_query($sql); echo "<script language=\"javascript\">alert('插入成功');history.go(-1)</script>";}include("head.php");?><SCRIPT language=javascript>function CheckPost(){ if (myform.user.value=="") { alert("请输入用户"); myform.user.focus(); return false; } if (myform.title.value.length<5) { alert("请输入标题"); myform.title.focus(); return false; } if (myform.content.value=="") { alert("请输入内容"); myform.content.focus(); return false; }}</SCRIPT> <form action="add.php" method="post" name="myform" onsubmit="return CheckPost();"> 用户<input type="text" size="10" name="user" /><br> 标题<input type="text" name="title" /><br/> 内容<textarea name="content" cols="60" rows="9"></textarea><br/> <input type="submit" name="submit" value="提交"/> </form>

