我有一个包含4个项目的html表单。php mysql插入条件判断
title
和content
是必需的。
link
和image
是可选的。
所以这是我写的,但我不能在我的数据库中插入数据。 我的条件声明中的url和image是否有错误?谢谢
if($_SERVER['REQUEST_METHOD'] == "POST") {
$ttt = strlen(htmlspecialchars(trim($_POST['title'])));
$ccc = strlen(htmlspecialchars(trim($_POST['content']))); // count title and content charters
$title = htmlspecialchars(trim($_POST['title']));
$content = htmlspecialchars(trim($_POST['content']));
$url = htmlspecialchars(trim($_POST['url']));
$image = htmlspecialchars(trim($_POST['image']));
if($url!=''){
if (!preg_match('|^(ht|f)tp(s?))://|', $url){
echo "wrong";
mysql_close($db);
}
} // if $url is not empty, judge is it began as a http:// ? else close the db link
if($image!=''){
if (!getimagesize($image)){
echo "wrong";
mysql_close($db);
}
} // if $image is not empty, use getimagesize judge is it a real image? else close the db link
if(($ttt > 2 && $ttt < 201) && ($ccc > 29 && $ccc < 1001)) {
$sql= "INSERT INTO msg (title, content,image,link) VALUES ('".$title."','".$content."', '".$image."', '".$url."')";//if title charters between 3-200 and content charters between 30-1000, do insert into thing
if(mysql_query($sql))
{
echo "insert done";
}else{
echo "insert wrong";
}
}else{
echo "your title or content is out of the words limit";
}
}
mysql_close($db);
哪里链接从何而来?也许它应该是$ url而不是$ link – Ibu 2011-05-09 17:49:39
如果我们能够看到'$ sql'的实际值,那将是有帮助的,否则我会说这是你的问题,你实际上没有写任何SQL。 – Endophage 2011-05-09 17:51:04
@Ibrahim Diallo,谢谢。这是一个错误,但我再次尝试,仍然没有工作。 – cj333 2011-05-09 17:52:53