-1

mysql_fetch_array not working in my code :- I got an error like this ...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\finalreports\generatereport.php on line 38

My code is So far ....

if(array_key_exists('server_guid',$_GET))
{
    $guids = $_GET['server_guid'];
    $guid_array = explode(",",$guids);

    //$reporttype = "Server Resources";

    for($i=0 ; $i<count($guid_array); $i++)
    {
        $query = "select vid from vendor_registration where bussname='".$guid_array[$i]."'";
        $result = mysql_query($query);



        while($row = mysql_fetch_array($result))
        {
            $name_array[$i] = $row[0];

        }
    }
}
hakre
  • 193,403
  • 52
  • 435
  • 836
John
  • 175
  • 1
  • 1
  • 12
  • 1
    Hello [Bobby Tables](http://bobby-tables)! – Marc B Sep 01 '11 at 17:48
  • @David, you keep posting questions full of SQL-injection holes, please see: please see: http://stackoverflow.com/questions/332365/xkcd-sql-injection-please-explain and http://stackoverflow.com/questions/5811834/how-to-prevent-sql-injection-with-dynamic-tablenames and stop injecting unescaped user data into a query. – Johan Sep 02 '11 at 13:13

2 Answers2

5

Make sure the result is not tainted:

$result = mysql_query($query) or die(mysql_error());
Naftali
  • 144,921
  • 39
  • 244
  • 303
2

Your query may be returning an error:

if (($result = mysql_query($query)) === false) {
    echo "Error running query: " . mysql_error() . "\n";
}
Sean Bright
  • 118,630
  • 17
  • 138
  • 146