Solved

please help with error supplied argument is not a valid MySQL result resource

Posted on 2004-04-20
6
283 Views
Last Modified: 2008-03-06
Hi guys can you help me out please, i am not sure whats up with this error, code is listed below.
Working with php 4.3.6 running Apache 2.0.49 on XP

if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM Athletes",$db);

    while ($myrow = mysql_fetch_array($result)) {

      printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["AthleteID"], $myrow["Name"], $myrow["Address"]);

        printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["AthleteID"]);

    }

  }
0
Comment
Question by:jess_z0
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:CosminB
ID: 10866975
you could either try
   $result = mysql_query("SELECT * FROM Athletes");
   or make sure $db is the resource link identifier

also you could do
   $result = mysql_query("SELECT * FROM Athletes");
   if (!result)
   {
     echo 'MYSQL ERROR: ', mysql_error(); //this will apear if you have an error in your sql sintax(wrong table name or stuff like that)
   }



use this script and tell me what is says:
if (!$id) {
    // print the list if there is not editing
    $result = mysql_query("SELECT * FROM Athletes");
    if (!result)
   {
     echo 'MYSQL ERROR: ', mysql_error(); //this will apear if you have an error in your sql sintax(wrong table name or stuff like that)
   }
    while ($myrow = mysql_fetch_array($result))
   {
      printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["AthleteID"], $myrow["Name"], $myrow["Address"]);
       printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["AthleteID"]);
    }
}
0
 

Author Comment

by:jess_z0
ID: 10867099
thanks for the script mate! much appriecated your help

from the script at the bottom you asked me to run, this is the response, same error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\display2.php on line 123
0
 
LVL 6

Accepted Solution

by:
CosminB earned 250 total points
ID: 10867139
add this:
echo 'MYSQL ERROR: ', mysql_error();
right before the while and see if it says anything
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jess_z0
ID: 10867190
i have used this code before so i am not sure why this is happening.

why is it not recognising the fuctions, is something screwed up with this installation?

thanks
jess
0
 

Author Comment

by:jess_z0
ID: 10867217
ok good work!
so it is saying no database is selected
0
 
LVL 10

Expert Comment

by:eeBlueShadow
ID: 10867307
you need to add a

mysql_select_db("yourDatabaseName", $db);

just after the mysql_connect line.

But you probably got that by now
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question