"The title of this thread has been changed to make the problem clearer to experts and others searching for similar threads."
MODERATOR
This will do it. I changed the order of the code:
1. first check if this script is called due to a submit, if so:
a. connect to MySQL server and db
a select with the appropriate WHERE attribs
b. display the found data
2. (re)display the form
[php]<?php
// check if form is posted
if (isset($_POST['submit']) AND isset($_POST['location'])) {
// sanitize the POSTed value
$location = strip_tags(trim($_POST['location']));
// connect to server and db
include('my_conn.php');
// Select all categories from country table
$query = "SELECT * FROM country, location
WHERE location.location = '$location'
AND location.countryID = country.countryID";
$result = mysql_query($query)
or die("SELECT error: ".mysql_error());
// retrieve and display all results
while($row = mysql_fetch_array($result)) {
echo "COUNTRY ID: {$row['countryID']} <br>" .
"COUNTRY : {$row['country']} <br><br>";
} // END While
} // END if(isset ....
// re-display the form
echo "<html><head><title> Whereabouts</title></head><body>";
/*create form*/
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>\n";
echo "<input type='text' name='location'>\n";
echo "<input type='submit' name='submit' value='submit'>
</form>\n\n";
echo "</body></html>";
?>[/php]
Have fun with it.
If you consider to make this into a full-fledged application, it will be worth to look at Ajax to do the asynch table lookup and display without doing a page refresh.
Ronald :cool: