Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Discussion in 'MySQL' started by phpnewbie, Jan 28, 2008.

  1. #1
    Hi there!

    A total newbie in php... We have a register over our resellers.
    The hostingcompany where our website is currently hosted has just upgraded the PHP version to the latest one.

    After this upgrade I got the following error:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    when trying to access a reseller.

    A bit from the code (that an consultant has wrote like 3 years ago):



    <? $result = mysql_query("SELECT * FROM retailer WHERE regionID=$regionID ORDER BY regionID DESC, isHeadOffice DESC, name"); ?>

    <? while($retailer = mysql_fetch_array($result)){ ?>

    Please help! :)
     
    phpnewbie, Jan 28, 2008 IP
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Doesn't the query itself give an error? Or the mysql_connect or mysql_select_db instructions?

    Try something like this and see what result it gives you:

    $result = mysql_query("SELECT * FROM retailer WHERE regionID=$regionID ORDER BY regionID DESC, isHeadOffice DESC, name") or die("MySQL error : ".mysql_errno()." - ".mysql_error());
     
    CreativeClans, Jan 28, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    <? $result = mysql_query("SELECT * FROM retailer WHERE regionID='$regionID' ORDER BY regionID DESC, isHeadOffice DESC, name"); ?>
    PHP:
    May be missiong single quotes for $regionID is a reson.
     
    rohan_shenoy, Jan 28, 2008 IP
  4. ayahhelmy

    ayahhelmy Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if $regionID is a string, you should put a single quote before and after the variable. But if $regionID is an integer value, your code is correct.

    Just make sure that it's really an integer value.

    Maybe ....regionID = " . intval($regionID) . " ORDER BY would help.
     
    ayahhelmy, Jan 31, 2008 IP