Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用表行时出现Mysql PHP错误_Php_Mysql - Fatal编程技术网

调用表行时出现Mysql PHP错误

调用表行时出现Mysql PHP错误,php,mysql,Php,Mysql,我有一个非常简单的请求,不知道为什么它是错误的: if ($_GET['linklabel'] !== '') { $query = "SELECT templateid FROM pages WHERE linklabel = {$_GET['linklabel']}"; $result=mysql_query($query); $templateid = $result['templateid']; echo $templateid;

我有一个非常简单的请求,不知道为什么它是错误的:

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']有问题

mysql\u query()返回语句句柄,而不是实际数据。您必须先获取数据行,然后才能从查询结果中访问各个字段:

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$templateid = $result['templateid'];
还请注意,您非常容易受到sql注入攻击,如果这种攻击发生在面向公众的网站上,您可能会在很短的时间内遭到攻击。

mysql\u query()返回一个语句句柄,而不是实际数据。您必须先获取数据行,然后才能从查询结果中访问各个字段:

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$templateid = $result['templateid'];

还要注意的是,您非常容易受到sql注入攻击,如果这种攻击发生在面向公众的网站上,您可能会在很短的时间内遭到攻击。

尝试将$query行更改为:

$query = "SELECT templateid FROM pages WHERE linklabel = '{$_GET['linklabel']}'";

请注意附加的引号。

尝试将$query行更改为:

$query = "SELECT templateid FROM pages WHERE linklabel = '{$_GET['linklabel']}'";
请注意附加的引号