FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

[mySQL] Error I cannot Debug

 


NewGuyinTown
OK guys...

I got an error message
Quote:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource


and my code, from the beginning to where it crashes, is
Code:

<?php
$dbh=mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$db");
$result = mysql_query("SELECT * FROM $tab");
//$num = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){?>


I executed the script select from $tab in mySQL and it works, but when I used php to execute it gives me an error. I spent hours trying to debug this already.

I also tried num_rows and that does work. I have 2 rows of data in the table.

Can someone explain to me what's wrong.

Thank you.
Rhysige
Code:

<?php
$dbh = mysql_connect ("localhost", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$db");
$result = mysql_query("SELECT * FROM $tab");
//$num = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
?>


Ok lets look into a few possibles.

1/ mysql_select_db ("$db");
The specified variable when connecting to the DB was $dbh
2/ it will return that error if whats going into mysql_fetch_array() is not a resource AKA has no data being retrieved. Where is $tab sepecified?
n0obie4life
mysql_select_db( $dbname, $dbh );

name of db, database link (the connect code).

And are you giving the full code?

I see missing parts here and there.

What's $tab? IF it's not a var, there's something wrong.
NewGuyinTown
I found out what's wrong... It was at the selecting part. I didn't give the any users the selecting privileges... Confused I was looking at my script for more than 2 hours, changing it, testing it... There wasn't any problem with my script... Ugh.

Yeah... it wasn't full the code... I copied from the mysql section to the error.

Thank you for trying to help.
Related topics
Mysql error!
Fatal error: Cannot instantiate non-existent class:
MySql error: Column count doesn't match value count at row 1
MySQL error
MySQL error
phpBB Error, seems to be a MYSQL DB error...
[solved] Weird mysql error
Error connecting to mysql ; please help
MySQL error 1604
phpbb - what does this error msg mean?
Suppressing mysql error
Fatal error: Cannot instantiate...
Mysql Error
Forum Avatar error
Mysql error: Warning: mysql_num_rows():
mysql error
Urgent! MySQL error!
[FIXED]MySQL Access , Direct Access Login Failure
MYSQL Ajax im Installation Error
Cant access admin area after updateing to 2.0.15
PHP script has MSQL access denied
Problème depuis "Big plantage" le 1er plantage du
Help...phpMyAdmin trouble
MySQL Error#: 1130 - help
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.