Jump to content

Archived

This topic is now archived and is closed to further replies.

Crashthatch

mysql_fetch_row

Recommended Posts

How do I use the mysql_fetch_row function? It seems to have worked in all of my other scripts, but not in this one.

I get this error:

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:webpageswebphpquestmain.php on line 20

 

This is the offending line:

 

$old_location = mysql_fetch_row(mysql_query(\"SELECT location FROM qu_user WHERE user=$cuser\"));

 

I try to print the result like this:

 

echo \"You have moved from $old_location\";

 

The same goes for mysql_fetch_object.

 

I have a feeling I have overlooked somthing really simple, but I cant figure out what it is.

 

Any help appriciated, thanks.

Share this post


Link to post
Share on other sites

$result = mysql_query("SELECT location FROM qu_user WHERE user=\'$cuser\'");

$old_location = mysql_fetch_row($result); 

 

This should fix the error!

Share this post


Link to post
Share on other sites

Actually, crashthatch\'s method would work fine unless the query returned FALSE (meaning it failed; usually a syntax error). Try using quotes around $cuser in the query.. like this:

$old_location = mysql_fetch_row(mysql_query("SELECT location FROM qu_user WHERE user=\'$cuser\'"));

 

Hope that helps.

Share this post


Link to post
Share on other sites

Cheers guys.

 

I messed around in PHPmyadmin with quotes and spaces, then changed it to:

 

$old_location = mysql_fetch_row(mysql_query (\"SELECT location FROM qu_user WHERE user = \'$cuser\' \"));

 

I\'m sure I\'ll be back soon when I get another problem. \'til then.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.