I'm a beginner and I have a error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\VertrigoServ\www\index.php on line 35

and the code...

$sresult = mysql_query("SELECT code, location FROM banners");
while ($row_s = mysql_fetch_array($sresult))
{
    $banner[$row_s["location"]]=$row_s["code"];
}
link|improve this question
feedback

2 Answers

Something is wrong with the query. try:

$result = mysql_query("..");
if(!$result){
  echo "Query error: " . mysql_error();
}
link|improve this answer
1  
or die() :-( :-( phpfreaks.com/blog/or-die-must-die -- I never understood why people keep using this ... Or even started using it in the first place... – Carpetsmoker Mar 16 '11 at 20:27
Agreed on die(), I, personally, have NEVER used it in my own code, but it was the first thing that popped in mind when writing here, strange :) – Martins Briedis Mar 16 '11 at 20:34
Alright. You are forgiven. – Carpetsmoker Mar 16 '11 at 20:41
feedback

Try this

$sresult = mysql_query("SELECT code, location FROM banners");
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
while ($row_s = mysql_fetch_array($sresult))
{
    $banner[$row_s["location"]]=$row_s["code"];
}

And check what the error is.

link|improve this answer
Thank you very much :* – Mihail Znov Mar 16 '11 at 20:22
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.