这是我写的一个很简单的记事本代码,代码比较幼稚刚学php,mysql一个月不到,师傅让写的~~~现在我的问题是要对留言板块加一个校验功能,比如留言内容不能过少,留言不能为空,过滤掉一些乱码,只写标题不写内容或者只写内容不写标题不能提交等。这一类代码要怎么写??大家帮忙写个例子或者推荐一些这方面的资料教程,小弟谢过了~~~~
<html>
<head>
<title>
test
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div align="center"><b><font size="6" face="宋体" color="#CC0000">欢迎你的到来</font></b>
<br>
<hr>
</div>
<form name="form1" method="post" action="">
<p>标题:
<input name="textfield" type="text" size="30">
</p>
<p>内容:</p>
<p> <textarea name="textarea" cols="30" rows="10"></textarea>
</p>
<p>
<input type="submit" name="submit" value="提交">
<input type="reset" name="cancel" value="取消">
</p>
<p> </p>
</form>
<?php
$title=$_POST["textfield"];
$content=$_POST["textarea"];
$host="192.168.12.50";
$user="root";
$pwd="123456";
$db=mysql_connect($host, $user, $pwd) or die('Could not connect: ' . mysql_error());
mysql_query("SET NAMES UTF8", $db);
mysql_select_db("xujun",$db);
$sql="INSERT INTO notepad (biaoti,neirong) VALUES ('$title','$content')";
mysql_query($sql,$db);
mysql_close($db);
?>
</body>
</html>
<html>
<head>
<title>
test
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div align="center"><b><font size="6" face="宋体" color="#CC0000">欢迎你的到来</font></b>
<br>
<hr>
</div>
<form name="form1" method="post" action="">
<p>标题:
<input name="textfield" type="text" size="30">
</p>
<p>内容:</p>
<p> <textarea name="textarea" cols="30" rows="10"></textarea>
</p>
<p>
<input type="submit" name="submit" value="提交">
<input type="reset" name="cancel" value="取消">
</p>
<p> </p>
</form>
<?php
$title=$_POST["textfield"];
$content=$_POST["textarea"];
$host="192.168.12.50";
$user="root";
$pwd="123456";
$db=mysql_connect($host, $user, $pwd) or die('Could not connect: ' . mysql_error());
mysql_query("SET NAMES UTF8", $db);
mysql_select_db("xujun",$db);
$sql="INSERT INTO notepad (biaoti,neirong) VALUES ('$title','$content')";
mysql_query($sql,$db);
mysql_close($db);
?>
</body>
</html>
function ufun($str)
{
$strsql=array("'",";","union","/","select","update","delete","insert","-","into"); //自己加
//循环数组
foreach ($strsql as $key=>$value)
{
if (eregi($value,$str))
return true;
}
return false;
}
function ufun($str)
{
$strsql=array("'",";","union","/","select","update","delete","insert","-","into"); //自己加
//循环数组
foreach ($strsql as $key=>$value)
{
if (eregi($val……
[/Quote
楼上的是过滤字符功能吗 我试了一下没有过滤掉啊??
1楼写的是通过循环查找$strsql里的字符是否在$str里出现过,出现过就返回false,都不存在就返回true.
........................................................................你说的关于过滤的完全是字符的基本操作,建议你看看php的基础教程.多写写知道了!
http://www.w3school.com.cn/php/func_string_strtr.asp
tr_replace
http://www.w3school.com.cn/php/func_string_str_replace.asp