Basic question on PhP-mysql code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skmit87
Forum Newbie
Posts: 1
Joined: Mon Oct 25, 2010 1:23 pm

Basic question on PhP-mysql code

Post 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...
InsanityNet
Forum Newbie
Posts: 6
Joined: Mon Oct 25, 2010 12:37 pm

Re: Basic question on PhP-mysql code

Post 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:
Last edited by InsanityNet on Mon Oct 25, 2010 10:32 pm, edited 2 times in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Basic question on PhP-mysql code

Post 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?
Post Reply