Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rows returned but empty variables?? 1

Status
Not open for further replies.

Elliott3

Programmer
Joined
Sep 5, 2002
Messages
347
Location
CA
I am running a query and it returns one record as it should (which i find out from mysql_num_rows()) but the variables are empty?? This is my code:
$sSQL = "SELECT pdf FROM articlesnew WHERE ID = " . $_GET['articleid'];
$result = @mysql_query($sSQL); //run the query
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$pdfFile = $row['articleDate'];
$num = mysql_num_rows($result);

$num returns 1
$pdfFile returns nothing
$GET['articleid'] returns the correct value

Any suggestions...am interested in any possibilties..

CES
 
The only things which will be in the $row variable will be the items from your SELECT statement... in this case there will be exactly one entry for
Code:
$row['pdf'];

For debugging purposes you'll probably get alot of mileage from
Code:
echo '<pre>';
print_r($row);

-Rob
 
I see two possible things wrong with this line:

$result = @mysql_query($sSQL);


First, you're using the &quot;@&quot; error-suppressiong operator. If you were getting an error from the function, you'd never know it. In my opinion, you should never use &quot;@&quot;.

Second, if MySQL were to return an error, you would not know it.

I recommend that you change the line to read:

$result = mysql_query($sSQL) or die(mysql_error());

This may or may not have any effect on your problem, though.


For checking on returned values, I recommend that for testing purposes you add the line:

print_r($row);

to the script immediately after the line where you invoke mysql_fetch_array(). It can give you a view of what you've fetched.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
thanks...i was just trying some different things and forgot that i left that like that..the line:
$pdfFile = $row['articleDate'];
actually does read:
$pdfFile = $row['pdf'];
and the var still returned nothing??


CES
 
New to php/mysql so i have never used print_r() before...this is what it returned:
Array ( [pdf] => )

CES
 
I figured it out...i was just trying to work on too many parts of the code at once and did something stupid. On related sillyness I never realized that the @ symbol suppressed errors. That was just the way my book shows that. Thanks for the tip. I appreciate it!

CES
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top