我又回来了,试图创建一个“自定义”博客系统。或者人们称之为CMS。这是我当前的代码:如何使用MySQL检查页面是否为空?
<?php
//include stuff here
$pid = $_GET['pageid'];
$data = mysql_query("SELECT * FROM entries WHERE id='$pid'") or die("MySQL died.");
mysql_real_escape_string($pid);
while($info = mysql_fetch_array($data))
{
if (!empty($info)) {
echo $info['data'];
}
else {
echo 'This page no existo.';
}
}
?>
发生什么事是它没有显示“This page no existo。”。作为'404'文本。 可以说有人试图直接去我的网站打字,但是输入了一个错误: localhost/blog /?pageid = 10 它没有显示404文本!
我在MySQL中有一行名为“data”。它由博客文章的这个数据组成。我也有一个称为ID的行,它是一个自动增量ID系统。 “真实”,工作页面ID为1.
谢谢, RBLXDev。
编辑: 的Vardump $信息: 的vardump:
array (size=10)
0 => string '1' (length=1)
'id' => string '1' (length=1)
1 => string 'Testing potatoCMS... and the title.' (length=35)
'title' => string 'Testing potatoCMS... and the title.' (length=35)
2 => string 'This is a test.
This is a new line.
This is a cookie.
You are getting fat.
FAT.<br />lol' (length=88)
'data' => string 'This is a test.
This is a new line.
This is a cookie.
You are getting fat.
FAT.<br />lol' (length=88)
3 => string '2013-02-02' (length=10)
'date' => string '2013-02-02' (length=10)
4 => string 'Unspecified' (length=11)
'author' => string 'Unspecified' (length=11)
呀,嗯...我有奇怪的占位符。
尝试使用您知道存在的数组中的索引,如:!空($ info ['id']) – David
这只是使pageid = 1“存在音符”。 – Raymonf
也考虑[正确转义的SQL上下文](http://bobby-tables.com/),或使用更容易使用[准备语句](http://stackoverflow.com/questions/60174/how-to-prevent -sql喷射在-PHP)。 – mario