0

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?

3
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by LastMitch
1

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

Edited by diafol

Votes + Comments
Nice! I didn't notice til now
0

@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.

Edited by LastMitch: grammer

0

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>"; 
    ?>
0

@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' ";

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.