Page 1 of 1

Basic question on PhP-mysql code

Posted: Mon Oct 25, 2010 1:27 pm
by skmit87
Hi All,

i am facing the following issue in my code below:
$dbQuery = "SELECT * from product where Title=\"$blobId\"";


$query_result=mysql_query($dbQuery) or die (mysql_error());
echo $query_result; //I see that a "resource Id 2 is coming up


$result = mysql_fetch_array($query_result) or die('no such data') ; //Its always saying no such data though the above query works fine in MYSQL command prompt.

If you see the Mysql_fetch_arraly always goes into the die mode. It is to be noted that the above query works in Mysql command prompt. Also the $query_result has value as resource id #2. What seems to be the problem here kindly guide me...

Re: Basic question on PhP-mysql code

Posted: Mon Oct 25, 2010 1:45 pm
by InsanityNet
Do you know that you are getting results? It is possible for it to be valid, but fetch no rows.
Try hard coding the sql to return a row.

EDIT
Just realized that my answer is compleatly irrelevant to your issue. :banghead:

Re: Basic question on PhP-mysql code

Posted: Mon Oct 25, 2010 6:11 pm
by califdon
Instead of trying to echo the result (which is an array, if it exists, so you can't echo it), use the PHP function print_r($result) to help debug.

But specifically to your error, the query looks OK and you say it works in command line, but it's failing in PHP, so the first thing I'd check is your connection, which you haven't shown us. Probably there's an error in your mysql_connect function or your mysql_select_db function. Do you have an "or die()" on those?