Warning: mysql_fetch_array()

Discussion in 'MySQL' started by dutch1, Jan 1, 2010.

  1. #1
    I have the following warning that comes up when I try to load the site and have no idea why this is happening.

    Can someone help?

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/mysite.com/config.php on line 22

    Here is the config.php file:

    <?php
    // mySQL information
    $server = 'localhost'; // MySql server
    $username = ''; // MySql Username
    $password = '' ; // MySql Password
    $database = ''; // MySql Database

    // The following should not be edited
    $con = mysql_connect("$server","$username","$password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("$database", $con);

    //mysql_query("UPDATE ava_games SET height='300' WHERE height='0'") or die (mysql_error());



    //
    $sql = mysql_query("SELECT * FROM ava_settings");
    $row = mysql_fetch_array($sql);
    $site_name = $row['site_name'];
    $site_description = $row['site_description'];
    $site_keywords = $row['site_keywords'];
    $site_url = $row['site_url'];
    $seo_on = $row['seo_on'];
    $template_url = $row['template_url'];
    $max_results = $row['max_results'];
    $image_height = $row['image_height'];
    $image_width = $row['image_width'];
    $adsense = $row['adsense'];
    $cat_numbers = $row['cat_numbers'];
    $email_on = $row['email_on'];
    $add_to_site = $row['add_to_site'];
    $plays = $row['plays'];
    $language = $row['language'];
    $featured = $row['featured_games'];
    $play_limit = $row['play_limit'];
    $adsense_id = $row['adsense_id'];
    $new_plays = 4;
    //

    I have left out my password, etc for obvious reasons

    Line 22 - $row = mysql_fetch_array($sql);

    Any help that can be offered is greatly appreciated.

    Thanks,
    Gerald
     
    dutch1, Jan 1, 2010 IP
  2. QuackWare

    QuackWare Member

    Messages:
    245
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #2
    QuackWare, Jan 1, 2010 IP
  3. dutch1

    dutch1 Peon

    Messages:
    357
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks QuackWare.

    I checked it out, but didn't find an answer to this particular problem.

    Anybody else with any ideas?
     
    dutch1, Jan 2, 2010 IP
  4. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #4
    put like this with "@"
    Line 22 - $row = @mysql_fetch_array($sql);
     
    crivion, Jan 3, 2010 IP
  5. dutch1

    dutch1 Peon

    Messages:
    357
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks crivion.

    I added the "@" but nothing happens, just the line doesn't show up anymore.

    The site still doesn't load
     
    dutch1, Jan 3, 2010 IP
  6. QuackWare

    QuackWare Member

    Messages:
    245
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #6
    Did you read this quote from the page I gave? It seemed to solve the problem for those who were posting. Basically add the "or die" part to give a more descriptive error message and the problem is most likely related to your syntax. Here is the quote.

     
    QuackWare, Jan 3, 2010 IP
  7. zro

    zro Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Try to put a WHERE statement in the query

    $sql = mysql_query("SELECT * FROM ava_settings");
     
    zro, Jan 3, 2010 IP
  8. dutch1

    dutch1 Peon

    Messages:
    357
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks to those who are trying to help, but I am really very new at using PHP and have no experience with mysql.

    Does anyone have a solution to my problem?

    The page won't load, but instead I get this message

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/mysite.com/config.php on line 22

    Line 22 is:

    $row = mysql_fetch_array($sql);

    Thanks
     
    dutch1, Jan 3, 2010 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    There will be a problem with the query. Before that line, put
    if(!$sql) die(mysql_error());
    PHP:
     
    JAY6390, Jan 3, 2010 IP
  10. dutch1

    dutch1 Peon

    Messages:
    357
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks

    This is what comes up now

    No database selected
     
    dutch1, Jan 3, 2010 IP
  11. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Then the problem is that this line isn't working
    mysql_select_db("$database", $con);
    PHP:
    check what $database contains if anything
    Also, you con't need the " " around it
     
    JAY6390, Jan 3, 2010 IP
  12. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #12
    That error is usually because it failed connecting to the db somewhere along the line, make the sure db exists and that you entered the db info correctly.

    Also you don't need the double quotes around the variables.

    Use this code, and reply with the errors (if any to debug).

    Replace this:

    // The following should not be edited
    $con = mysql_connect("$server","$username","$password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("$database", $con); 
    PHP:

    With this:

    
    $con = mysql_connect($server,$username,$password) or die(mysql_error());
    mysql_select_db($database, $con); or die(mysql_error());
    PHP:
     
    danx10, Jan 3, 2010 IP
  13. dutch1

    dutch1 Peon

    Messages:
    357
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks everybody it's fixed

    Please close thread
     
    dutch1, Jan 4, 2010 IP