I want to send the content of the form from my HTML page to the PHP page using AJAX. It seems like the AJAX form is working, at can I see that it reacts when the button is pushed. However, the PHP page doesn't not receive the content of the form, because not happens to the query. Can you please tell me what I'm doing wrong? Is it in the PHP page or is it the AJAX code?
HTML page: jQuery-ajax.html
Form:
<form action='AjaxDifferentBids.php' method='post' id="form1">
<input type='text' id="name" name='name'/><br>
<input type='text' id="email" name='email'/><br>
<input type='button' name='submit' value='Submit' id="submit" />
</form>
AJAX code:
$(function(){
$('#submit').click(function(){
$.ajax({
type:'POST',
url: 'AjaxDifferentBids.php',
data: $('#form1').serialize(),
success: function(response) {
$('.MyJobsResultsRight').hide();
$('.MyJobsResultsRightOtherBid').show();
$('.MyJobsResultsRightOtherBid').find('.form_result').html(response);
}
});
});
});
PHP page: AjaxDifferentBids.php
<?php
//set connection variables
$host = "";
$username = "";
$password = "";
$db_name = ""; //database name
$mysqli = new mysqli($host, $username, $password, $db_name);
//check if any connection error was encountered
if(mysqli_connect_errno()) {
echo "Error: Could not connect to database.";
exit;
}
if(isset($_POST['Submit'])){ //the the user submitted the form
//include database connection
include 'Connection.php';
$query = "SELECT * FROM firms WHERE email = '".$_POST['email']."'";
//execute the query
if( $mysqli ->query($query) ) {
//if saving success
echo "Succes";
}else{
//if unable to create new record
echo "Database Error: Unable to create record.";
}
//close database connection
$mysqli->close();
} ?>
Thank you very much!!