I'm trying to use a drop down form box & select statements to gather certain pieces of information from my database however i'm recieving the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /study/comp/c3329871/webpages/mysql/queryContinent.php on line 26

This is the code from my php file

<?php 

  //Include the connection details, open $connection and select database
include ("./php/connection.php");

 //Get the Initial Letter passed 
$dispContinent = $_GET["selContinent"];

//If the variable $dispContinent is NOT EQUAL to ALL
if ($dispContinent != "All" )
{ 
$query = $query." 'SELECT * FROM `symbols` WHERE continent ='$dispContinent'";
}

Echo $query;
// create query using the initial letter from above and a % wildcard
$query = "'SELECT * FROM 'symbols' WHERE 'continent' = '$dispContinent' "; 

// execute query 
$result = mysql_query($query);




 print "<table border=1>"; 
 while($row = mysql_fetch_array($result)) { 
     print "<tr>"; 
     print "<td>".$row['id']."</td>"; 
     print "<td>".$row['country']."</td>"; 
     print "<td>".$row['animal']."</td>"; 
     print "<td>".$row['continent']."/td>";
     print "</tr>"; 
 } 
 print "</table>"; 
?>

and here is the HTML form (I know it's not correct and won't validate but i'll fix that later on)

<body>


 <form name="selContinent" id="selContinent" method="get" action="queryContinent.php">
 <select name="selContinent" form="selContinent">
   <option value="All">All</option>
   <option value="North America">North America</option>
   <option value="Asia">Asia</option>
   <option value="Australia">Australia</option>
      <option value="Europe">Europe</option>
 </select> 
  <input type="submit">
</form>
</body>

Any ideas on how to fix this error?

Member Avatar for diafol

You've quoted your fieldnames - use backticks instead: `fieldname`

commented: Nice! I didn't notice til now +5
Member Avatar for LastMitch

@jvause3

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /study/comp/c3329871/webpages/mysql/queryContinent.php on line 26

It means that your mysql_fetch_array() function is not fetching this $result

Another words The error means your $result is not connected to the DB or not selecting any data.

Ok removed the backticks (or so I think I have) and still recieving the same error. The if statement is "supposed" to help with debugging and on the php page i get the following:

'SELECT * FROM symbols WHERE continent ='Australia'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /study/comp/c3329871/webpages/mysql/queryContinent.php on line 26

I know the continent is Australisia but the Database provided has it down as Australia

All that really tells me is that the menu works in selecting the right option, but i'm not getting anything back from the database.

   <?php 

      //Include the connection details, open $connection and select database
    include ("./php/connection.php");

     //Get the Initial Letter passed 
    $dispContinent = $_GET["selContinent"];

    //If the variable $dispContinent is NOT EQUAL to ALL
    if ($dispContinent != "All" )
    { 
    $query = $query." 'SELECT * FROM symbols WHERE continent ='$dispContinent'";
    }

    echo $query;
    // create query using the initial letter from above and a % wildcard
    $query = "'SELECT * FROM symbols WHERE continent = '$dispContinent' "; 

    // execute query 
    $result = mysql_query($query);


     print "<table border=1>"; 
     while($row = mysql_fetch_array($result)) { 
         print "<tr>"; 
         print "<td>".$row['id']."</td>"; 
         print "<td>".$row['country']."</td>"; 
         print "<td>".$row['animal']."</td>"; 
         print "<td>".$row['continent']."/td>";
         print "</tr>"; 
     } 
     print "</table>"; 
    ?>
Member Avatar for LastMitch

@jvause3

'SELECT * FROM symbols WHERE continent ='Australia'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /study/comp/c3329871/webpages/mysql/queryContinent.php on line 26

I know the continent is Australisia but the Database provided has it down as Australia

How did you enter it? Australisia or Australia? If you enter Australisia then it will be in the database. If you fetch it then it will be Australisia not Australia.

There shouldn't be ' in front SELECT

$query = $query." 'SELECT * FROM symbols WHERE continent ='$dispContinent'";

$query = "'SELECT * FROM symbols WHERE continent = '$dispContinent' ";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.