Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-20
6
Medium Priority
?
286 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 1000 total points
ID: 10867139
add this:
echo 'MYSQL ERROR: ', mysql_error();
right before the while and see if it says anything
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

704 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