php簡單留言板代碼

來源:互聯網
上載者:User

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">&nbsp;</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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.