Solved

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

Posted on 2004-04-20
6
273 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
The viewer will learn how to dynamically set the form action using jQuery.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now