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
Solved

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

Posted on 2004-04-20
6
282 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
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.

856 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