2012-08-23 61 views
-1

任何人都可以帮助我。我得到的错误警告:mysql_fetch_assoc():提供的参数不是一个有效的MySQL结果资源在...警告:mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源

我的代码:

include("../connection.php"); 

$con=mysql_connect($host, $username, $password, $db_name) or die ("insert error message"); 


mysql_select_db("db") or die ("Couldn't find database"); 

$story=mysql_query("SELECT hand_story.username, hand_story.age, hand_story.occupation,  
hand_story.star_sign, hand_story.cats_and_dogs, hand_story.holiday, hand_story.single, 
hand_story.story, big_hand_images.username, big_hand_images.url 
FROM hand_story  
INNER JOIN big_hand_images 
ON hand_story.username=big_hand_images.username 
WHERE big_hand_images.url='$guess'"); 

echo (mysql_error()); 

while($row = mysql_fetch_assoc($story)){ 

$age = $row['age']; 
$occupation = $row['occupation']; 
$star_sign = $row['star_sign']; 
$cats_and_dogs = $row['cats_and_dogs']; 
$holiday = $row['holiday']; 
$single = $row['single']; 
$story = $row['story']; 
} 

我可以附和了从数据库中的结果,所以它的工作,但我无法弄清楚为什么我也收到错误信息。

任何人都可以帮忙吗?这与我的SQL查询有关吗? 钽

回答

0

试试这个:'”。$猜测 “'
WHERE big_hand_images.url =”);

当心MySQL的注射

+0

变量插值将在双引号字符串中正确工作 –

0

每当你拿到类型的错误,知道在你的SQL查询中有错误,因此MySQL没有返回行。

解决方案:复制sql语句,并运行在phpmyadmin或类似的东西,并确保查询在那里工作。打印查询将显示PHP发送的内容到MySQL

+0

我试过了,它返回一行。当我得到一行返回时,我能够回显结果。 Sti – user1022772

+0

是否在你的php中使用echo($ sql)'?输出是什么样的? '$ guess'中的值是多少? – codingbiz

+0

干杯。我可以看到我现在做了什么。正在使用相同的变量名称 - $故事。将我的查询的名称更改为$ story1,这样就消除了错误。欢呼你的帮助 – user1022772

0

我可以看到我现在所做的。

正在使用相同的变量名称 - $故事。将我的查询名称更改为$ story1,这样就消除了错误。

相关问题