可能重复:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
好的,这是我的密码。
<?php
include 'connect.php';
$id = addslashes($_REQUEST['id']);
$image = "SELECT * FROM images WHERE id=$id";
$result = mysql_query($image);
$imagearray = mysql_fetch_assoc($result);
$realimage = $imagearray['image'];
header("Content-type: image/jpeg");
echo $realimage;
?>该页面使用GET获取id,但它给出了以下错误:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a6289454/public_html/get.php on line 9
发布于 2012-02-11 23:47:54
var_dump(mysql_error());将帮助您找到错误消息。但最有可能的是你需要引号:
$image = "SELECT * FROM `images` WHERE `id`='".$id."'";发布于 2012-02-11 23:59:34
我认为问题可能出现在addslashes()中,请尝试使用mysql_real_escape_string()。
发布于 2012-02-12 00:10:48
为什么要在$_REQUEST['id']中添加斜杠?它应该是一个整数
试试下面的代码:
if(is_numeric($_REQUEST['id'])){
$q = "SELECT * FROM images WHERE id = " . $id; // Don't put variables in strings!
$rs= mysql_query($q) or die("There is an error in the query:<br>" . $q . "<br><br>The error is: ". mysql_error()); // Throw and error if there is one.
$result = mysql_fetch_assoc($rs);
} else { die('Not a valid ID'); }另外,为了更好的实践,请使用require_once('connect.php');而不是include 'connect.php';
https://stackoverflow.com/questions/9245086
复制相似问题