not a valid MySQL result... What's wrong with my 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
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

not a valid MySQL result... What's wrong with my code?

Post by SteveMellor »

This should be simple stuff and I'm probably missing something obvious (can't see the wood for the trees sort of thing) but all help is appreciated. I have a block of code that I am using for connection:

Code: Select all

mysql_select_db($database_dggb, $dggb);
				$query_member = "SELECT * FROM `membersBenefits` WHERE `active` = '1' ORDER BY `order` Asc";
				$member = mysql_query($query_member, $dggb);
				$row_member = mysql_fetch_assoc($member);
				$totalRows_member = mysql_num_rows($member);
There is definately a table called 'membersBenefits'. It definately has a field called 'active'. This connection works perfectly fine on my local server. I have just uploaded it and found the following error.

Code: Select all

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in join.php on line 28

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in join.php on line 29
My question of course is... what have I done wrong?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

See what this gives you..

Code: Select all

mysql_select_db($database_dggb, $dggb);
            $query_member = "SELECT * FROM `membersBenefits` WHERE `active` = '1' ORDER BY `order` Asc";
            $member = mysql_query($query_member, $dggb);
echo "The error is " . mysql_error();
            $row_member = mysql_fetch_assoc($member);
            $totalRows_member = mysql_num_rows($member);
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

I am getting
The error is
nothing else.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

mysql_error() returns an empty string when there isn't an error, so this makes it a little confusing. Did you post your actual code?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Have you got any rows in the table?
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

yep, that's it, and you can see it happening on the page http://ns7.sovdns.com/~dggborg/test/join.php.

The fact that there was no SQL error was what through me in the first instance. I thought it was a problem with the database but I can log into my PHPMyAdmin panel and see the table it's looking for. If you have a look through the rest of the site, (even though there's no data there at the moment) the same block of text has been used to connect the other pages and they work perfectly well.

The other thing that is so confusing is that it's running perfectly fine on my localhost.
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

jayshields wrote:Have you got any rows in the table?
Yep, there are 9 records in there.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Try this to see if it's the query..

Code: Select all

$query_member = "SELECT * FROM `membersBenefits`";
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

astions wrote:Try this to see if it's the query..

Code: Select all

$query_member = "SELECT * FROM `membersBenefits`";
Still getting it so I assume there is a problem with the table. I'm going to try droping it and puting the data in again.
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

Still no luck I'm afraid.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Is the name of your database membersBenefits by chance?
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

astions wrote:Is the name of your database membersBenefits by chance?
Nope.
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

I have solved it. Well, solved is not technically right. I have found a way around the problem by creating a new table (called 'memben') and dumping the data in that.

I have no idea why this happened and no idea what fixed it, but thanks to everyone (especially astions) who took an interest and at least tried to help :wink:
Post Reply