php簡單留言板代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php簡單留言板代碼</title>
</head>
<body>
<table width="98%" border="0">
<form id="form1" name="form1" method="post" action="comment/comment.php?nid=21">
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">
<label></label>
<label>
<textarea name="content" cols="40" rows="8" id="content"></textarea>
</label>
</td>
</tr>
<tr>
<td width="5%"><label>
<input name="code" type="text" id="code" size="8" />
</label></td>
<td width="95%"><label><img src="../inc/code/encode.php" onclick="javascript:this.src='../inc/code/encode.php';" /> </label>
輸入驗證碼</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="提交評論" /></td>
</tr>
</form>
</table>
$content = PostGet('content',1);
$tel = PostGet('tel',1);
$cname = PostGet('mail',1);
//$ip = getRealIp();
if( mb_strlen( $content ) > 100 || mb_strlen( $content )<5 )
{
MessAge('留言內容長度5-100字元');
}
else if( strlen($tel) <5 && strlen( $tel )>15 )
{
MessAge('聯絡電話錯誤!');
}
else if(!preg_match("/^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/",$cname))
{
MessAge('輸入正確的郵箱地址!');
}
else
{
$date = date("Y-m-d H:i:s");
$Db = new Db();
$sql = "Insert into cn_loupan_news_comment(nid,content,datetime,cname,ip) values('0','$content','$date','$cname','$tel')";
try{
$Db->query( $sql );
MessAge('謝謝你的建議,我們將儘快處理...!','/Complaints.php');
}catch (Execption $e ){
MessAge('發送資訊失敗!');
}
}
function PostGet($str,$post=0)
{
empty($str)?die('para is null'.$str.'!'):'';
if( $post )
{
return addslashes(htmlspecialchars(isset($_POST[$str])?$_POST[$str]:''));
}
else
{
return addslashes(htmlspecialchars(isset($_GET[$str])?$_GET[$str]:''));
}
}
?>
</body>
</html>