我有一个非常简单的请求,但我不知道为什么它是错误的:
if ($_GET['linklabel'] !== '')
{
$query = "SELECT templateid FROM pages WHERE linklabel = {$_GET['linklabel']}";
$result=mysql_query($query);
$templateid = $result['templateid'];
echo $templateid;
if ($result !== 0)
{
include($templateid.'.php');
}
else
{
include('404error');
}
}表中的templateid的VARCHAR值为test。浏览器说它找不到test.php文件
我打错什么了吗?
回显变量$templateid也不会输出任何内容,所以我认为$templateid = $result['templateid'];有问题
发布于 2012-01-12 11:11:22
mysql_query()返回语句句柄,而不是实际数据。您必须先获取数据行,然后才能从查询结果中访问单个字段:
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$templateid = $result['templateid'];还要注意的是,你很容易受到sql注入攻击,如果这是在一个面向公众的网站上进行的,你可能会在很短的时间内被攻击。
发布于 2012-01-12 11:11:43
尝试将$query行更改为:
$query = "SELECT templateid FROM pages WHERE linklabel = '{$_GET['linklabel']}'";请注意额外的引号。
https://stackoverflow.com/questions/8829624
复制相似问题