I am having some issues returning data from on page, using jQuery, PHP and MySQL. I would like to show the query results on the index.php page. The results are fetched from the database using getResults.php.
When I manually run the getResults.php?id=123 file, all works fine. In this case i'm seeing the results I would like to. However, when I want to post the 'id' 123 in a submit form on index.php, I don't see any results returned by jQuery / getResults.php. Only thing that changed is the URL: index.php?id=123. However, I'm not seeing any results or an error message...
Any one an idea?
getResults.php file
$search = mysql_real_escape_string( isset ($_POST['id']));
if ($search) {
$friend = mysql_query( " SELECT * FROM reviews WHERE fbuserid = '$search' ORDER BY datumtijd DESC" );
if ( $friend ) {
while ($row = mysql_fetch_array ($friend) ) {
echo "Show some results...";
}
} else {
echo "No matches found";
}
} else {
echo "Query not succesfull";
}
index.php file
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#submit").click(function) {
event.preventDefault();
$.ajax({
url:"getResults.php",
type:"GET",
data: "id="+this.value,
success: function(data) {
$("#results").html(data);
}
});
}
return false;
});
</script>
<div>
<form>
<input type="text" name="id">
<input type="submit" value="submit" id="submit">
</form>
</div>
<div id="results"></div>
EDIT: Thanks, all for your input. Nevertheless, I'm still not there... As you might notice, I'm not quite experienced with jQuery and PHP. See changes in scripts above. In short: - I added the false statement if ($query) is not succesfull; - Changed the $.post method into $.ajax; - Changed the GET into POST in the PHP file;
Any other suggestions?