SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Valid MySQL result resource error

    Does anyone know why the code below produces the error: Warning: Supplied argument is not a valid MySQL result resource in /home/sounds/public_html/cms/artists.php on line 29

    Here's the code:
    <?php

    $dbcnx = mysql_connect("localhost", "sounds_tomas", "tomaso1");
    mysql_select_db("archy");

    $artists = mysql_query("SELECT id, artist, instrument FROM artists");
    if ($artists) {
    echo("<P>Error retrieving artists from database!<BR>".
    "Error: " . mysql_error());
    exit();
    }

    while ($artist = mysql_fetch_array($artists)) {
    $id = $artist["id"];
    $name = $artist["artist"];
    $instrument = $artist["instrument"];
    echo("<LI>$name ".
    "[<A HREF='editartist.php?id=$id'>Edit</A>|".
    "<A HREF='deleteartist.php?id=$id'>Delete</A>]");
    }

    ?>

    Line 29 begins the while loop. Sure would appreciate it.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, posting your username and password isn't a good idea.

    Anyway, your error means that $artists isn't being set properly, so your SQL statement is prolly messed up. This could mean that id, artist, or instrument isn't a column in the table, or that artists isn't a table in the archy database.
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give me a little credit - I changed the username and password. Also, id, artist, and instrument are columns in the table, and artists is a table in the "archy" database.
    Anyway, thanks for your reply and I'll take a closer look. This script was previously working just swell but I've switched to a new host and am trying to reconfigure things there.

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your probably not connecting to the database if the query is fine.
    i've done that before.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always wonder why people do not always use:

    PHP Code:
    or die(mysql_error()); 
    If you do MySQL will spit out the error

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $artists mysql_query("SELECT id, artist, instrument FROM artists"); 
    if (
    $artists) { 
    echo(
    "<P>Error retrieving artists from database!<BR>"
    "Error: " mysql_error()); 
    exit(); 

    Also checking for if ($artist), this clause will print the error, even if the query is good. I think you mean

    PHP Code:
    $artists mysql_query("SELECT id, artist, instrument FROM artists"); 
    if (!
    $artists) { 
    echo(
    "<P>Error retrieving artists from database!<BR>"
    "Error: " mysql_error()); 
    exit(); 

    Take Sean's suggestion and change

    PHP Code:
    $artists mysql_query("SELECT id, artist, instrument FROM artists"); 
    to

    PHP Code:
    $artists mysql_query("SELECT id, artist, instrument FROM artists") or DIE(mysql_error()); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all. The error was caused because I simply was not conneting to the database. The control panel at our new host provided an incorrect connection string - that's my story anyway and I'm stikin' to it!
    Thanks also for the suggestions - will do.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •