Results 1 to 16 of 16

Thread: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Hi all i got a php script that works perfectly in my localhost but when i use it in a site which is in remote i get the following error:
    Code:
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/method/public_html/music/singerIndex.php on line 72

    When i load the page no output and i get the above error. Is there any connection problem here? or sql syntax ?I be happy if an expert tell me how to fix it.Thanks




    Code:
    <?php
    
    
    //alone script that reads folder but but not subfolder and wirtes it file name to db
    
    // change below is your assigned mySQL username
    $user = "root";
    
    // change to the pw below is your assigned mySQL password
    $pw = "";
    
    // change to the database you have permission to connect to
    $db = "method_music";
    
    
    
    //mysql_connect("localhost", "root", ""); 
    $mysql_access = mysql_connect("localhost", $user, $pw);
    mysql_select_db($db, $mysql_access);
    
    
    
    
    
    $query  = "select distinct artist from songs order by artist";
    $result = mysql_query($query);
    
    //echo $query;
    //exit(); 
    
    
    ?>
    
    <html>
    
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1">
    <title>Untitled </title>
    </head>
    
    <body>
    
    <br>
    
    <br>
    
    <br>
    
    <br>
    <br>
    <table border="1" cellspacing="1" width="100%"
    bordercolorlight="#008ED2" id="table1"
    style="BORDER-COLLAPSE: collapse">
        
        <tr>
            <td colspan="3" bgcolor="#323E8D"><p align="center"><font
            color="#FFFFFF"><b>:.Singers ..:</b></font></p>
            </td>
        </tr>
      <tr>
            <td valign="top"><table border="0" cellpadding="2">
                
            
      My code. The red line shows the line 72:
    <?
    //this line for dropdownbox
    $option = "";
    $numbers=0;
    while($row = mysql_fetch_assoc($result)) ==> error point
    {
    $numbers++; // counting number of records
    //This 2 line for drop downbox
    extract ($row);
        $option .= "<option value=\"$artist\">$artist</option>\r\n";
    
        //echo "<br>Id : {$row['id']} <br>" .
         //    "filename :{$row['filename']} <br>" .
        //     "artist : {$row['artist']} <br>" . 
        //     "album : {$row['album']} <br>" .
        //     "title : {$row['title']} <br><br>";
     
    
    ?>
    
    
               
    <tr>
                    <td style="BORDER-BOTTOM-STYLE: dotted"><a
                    href="albums.php?albumname=<?=strval( $row['artist'] );?>"><? echo $numbers; ?>=><?=strval( $row['artist'] );?></a> [<a
                    href="javascript:newWindow('RateSingers.php?SingerID=1378')">Rate
                    Me</a>] Hits:<b>???</b></td>
                </tr>
    
     
    
    
    <?
    
    
    } 
    
    
    ?>

  2. #2
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Try this in your query:
    Code:
    $query  = "select distinct `artist` from `songs` order by `artist`";
    noister
    <advertising link removed by moderator>

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Quote Originally Posted by noielen
    Try this in your query:
    Code:
    $query  = "select distinct `artist` from `songs` order by `artist`";
    Thank u for u reply. Unfortuently same error !! Is it connection problem ?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    You must have no data in your database.

  5. #5
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    what about:
    Code:
    $query = "select distinct(artist)... order by artist asc"
    noister
    <advertising link removed by moderator>

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Quote Originally Posted by penagate
    You must have no data in your database.
    i check mysql db using phpmyadmin and i see there are data!

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Quote Originally Posted by noielen
    what about:
    Code:
    $query = "select distinct(artist)... order by artist asc"
    Thank u for u reply.same error!

  8. #8
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    i have this error before, i just put `` before and after of my fieldnames and tables. now i used that all in my queries...
    noister
    <advertising link removed by moderator>

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    after
    PHP Code:
    $result mysql_query($query); 
    add
    PHP Code:
    if (!is_resource($result)) echo mysql_error(); 

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Quote Originally Posted by penagate
    after
    PHP Code:
    $result mysql_query($query); 
    add
    PHP Code:
    if (!is_resource($result)) echo mysql_error(); 
    Thank u for u reply. I get this error:


    No database selected


    I do not know what i am doing wrong!!

  11. #11
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    and thats....... obviously in your connection.
    noister
    <advertising link removed by moderator>

  12. #12
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    try this
    Code:
    $link = mysql_select_db($db, $mysql_access);
    $query  = "select distinct artist from songs order by artist";
    $result = mysql_query($query, $link);
    i'm not sure with this just try it.
    noister
    <advertising link removed by moderator>

  13. #13
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resour

    I think I know what it is, on a hosted machine the DB name is usually prefixed with your username, e.g.

    PHP Code:
    $db 'tony007_method_music'
    Last edited by penagate; Apr 28th, 2006 at 05:09 AM.

  14. #14
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    Quote Originally Posted by penagate
    I think I know what it is, nn a hosted machine the DB name is usually prefixed with your username, e.g.
    PHP Code:
    $db 'tony007_method_music'
    mybe
    noister
    <advertising link removed by moderator>

  15. #15
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resour

    You should be error checking every call to mysql which could fail. mysql_select_db() is the same as calling mysql_query('use dbname').
    Code:
    if (! mysql_select_db($db)) {
        echo(mysql_error());
        die;
    }
    
    if (! ($result = mysql_query($query)) {
        echo(mysql_error());
        die;
    }
    Last edited by visualAd; Apr 28th, 2006 at 09:25 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem:mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

    use dbname

Posting Permissions

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



Click Here to Expand Forum to Full Width