[SOLVED] Confusing 'not a valid MySQL result resource' error

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
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

[SOLVED] Confusing 'not a valid MySQL result resource' error

Post by mjseaden »

Dear All,

For this piece of code:

Code: Select all

$query5 = 'SELECT * FROM CommissionTermPayments WHERE CustomerID='.$row2['CustomerID'].' AND CommissionTermID='.$row4['CommissionTermID'];
        $myresult5 = mysql_fetch_array( $query5 );
        
        if(!$myresult5)
        {
            do_html_message('Error: Could not perform MySQL query - '.mysql_error());
            do_html_footer();
            exit();
        }
I get the following error:

Code: Select all

Warning: Supplied argument is not a valid MySQL result resource in /home/XXXX/public_html/sales.php on line 102
Line 102 is the mysql_query line. I have had a problem like this just previous to this, which I solved by substituting the variable '$result' for '$myresult'. It now works.

I've never had this problem before and this doesn't seem to work this time. It would be best to understand the underlying cause.

Can anyone elaborate on why it is doing this?

Many thanks

Mark
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

I'll also add that it is producing an error - however mysql_error() is returning an empty string.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

You are not actually querying the database so.....

Code: Select all

$query5 = 'SELECT * FROM CommissionTermPayments WHERE CustomerID='.$row2['CustomerID'].' AND CommissionTermID='.$row4['CommissionTermID'];

$query5res = mysql_query($query5);

$myresult5 = mysql_fetch_array( $query5res );
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

doh
Post Reply