Solved

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

Posted on 2004-04-20
6
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

751 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