sorry, this is my first post, and for some reason I did not have rights to modify my old one, there was an error in what I posted due to a typeo, this is the code that you should look at:
<!doctype html>
<?php
// php script that should get the ajax post
// and run the sql query
//host, username, password
$connection = mysql_connect('localhost','root','');
mysql_select_db('recipes');
//run query if post successful
$data = '';
if(isset($_POST['countrySelected']))
{
$var = $_POST['countrySelected'];
if($query = mysql_query("SELECT name FROM recipes2 WHERE country='%$var%'"))
{
while($d = mysql_fetch_array($query))
{
$data .= $data . '<div>' . $d['name'] . '</div>'; //incrementation .=
}
echo $data;
}
// if not successful print, echo report
}
else{
echo "<html><br /> <br /> <br />
***POST NOT SET****
<br /> <br /> <br /></html>";
}
?>
<!-- html code for display -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>change demo</title>
<style>
div {
color: red;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<!-- code for drop down menu -->
<select name="countries" id = "countries">
<option>Hungary</option>
<option>United States</option>
<option>Mexico</option>
<option >India</option>
</select>
<div> </div>
<script>
//javascript that detects when the button has been updated and retrieves the button option text value.
$( "select" )
.change(function () {
var str = "";
var countrySelectedStr = "";
$( "#countries option:selected" ).each(function() {
str += $( this ).text();
});
countrySelectedStr += "countrySelected=" + str;
$( "div" ).text( countrySelectedStr );
// ajax post
jQuery.ajax({
type: "POST",
url: "filterRecipes.php",
data: countrySelectedStr,
dataType: "text" ,
cache: false
});
})
.change();
</script>
</body>
</html>