i'm trying to get a simple contact form to work, i have successfully written my code without any apparent errors,created my database and linked it. but after filling in some values on the form and clicked the submit button, it seems as though the values were not posted to my database so the form keeps on showing this echo message "please fill names and email". i can't find any errors please help. thanks
i've tried renaming my database, removing the
if((isset($_POST['your_name'])&& $_POST['your_name'] !=''))
condition because it seems it not being met.
here is my get_response.php code
<?php
require_once("config.php");
if((isset($_POST['your_name'])&& $_POST['your_name'] !='') &&
(isset($_POST['number'])&& $_POST['number'] !='') &&
(isset($_POST['your_email'])&& $_POST['your_email'] !='') &&
(isset($_POST['subject'])&& $_POST['subject'] !='') &&
(isset($_POST['message'])&& $_POST['message'] !=''))
{
require_once("contact_mail.php");
$your_name = $conn->real_escape_string($_POST['your_name']);
$number = $conn->real_escape_string($_POST['number']);
$your_email = $conn->real_escape_string($_POST['your_email']);
$subject = $conn->real_escape_string($_POST['subject']);
$message = $conn->real_escape_string($_POST['message']);
$sql="INSERT INTO contact
(your_name, number, your_email, subject, message)
VALUES ('".$your_name."','".$number."','".$your_email."',
'".$subject."', '".$message."')";
if(!$result = $conn->query($sql)){
die('There was an error running the query [' . $conn->error . ']');
} else {
echo "Thank you! We will contact you soon";
}
} else {
echo "Please fill Names and Email";
}
?>
here is my contact.php form also
<form action="get_response.php" method="post">
<div class="row main-w3layouts-sectns">
<div class="col-md-6 w3-btm-spc form-text1">
<input class="form-control" type="text" name="your_name" placeholder="Enter Your Name" required="">
</div>
<div class="col-md-6 w3-btm-spc form-text2">
<input class="form-control" type="text" name="number" placeholder="Enter Phone Number" required="">
</div>
</div>
<div class="row main-w3layouts-sectns">
<div class="col-md-6 w3-btm-spc form-text1">
<input class="form-control" type="email" name="your_email" placeholder="Enter Your Email" required="">
</div>
<div class="col-md-6 w3-btm-spc form-text2">
<input class="form-control" type="text" name="subject" placeholder="Subject" required="">
</div>
</div>
<div class="main-w3layouts-sectns ">
<div class="w3-btm-spc form-text2 p-0">
<textarea class="form-control" placeholder="Enter Your Message Here" name="message"></textarea>
</div>
</div>
<button type="submit" class="btn mt-3">Submit</button>
<div class="response_msg"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#contact").on("submit",function(e){
e.preventDefault();
if($("#contact [name='your_name']").val() === '') {
$("#contact [name='your_name']").css("border","1px solid red");
} else if ($("#contact [name='number']").val() === '') {
$("#contact [name='number']").css("border","1px solid red");
} else if ($("#contact [name='your_email']").val() === '') {
$("#contact [name='your_email']").css("border","1px solid red");
} else if ($("#contact [name='subject']").val() === '') {
$("#contact [name='subject']").css("border","1px solid red");
} else if ($("#contact [name='message']").val() === '') {
$("#contact [name='message']").css("border","1px solid red");
} else {
$("#loading-img").css("display","block");
var sendData = $( this ).serialize();
$.ajax({
type: "POST",
url: "get_response.php",
data: sendData,
success: function(data){
$("#loading-img").css("display","none");
$(".response_msg").text(data);
$(".response_msg").slideDown().fadeOut(3000);
$("#contact").find("input[type=text], input[type=email], textarea").val("");
}
});
}
});
$("#contact input").blur(function(){
var checkValue = $(this).val();
if(checkValue != '') {
$(this).css("border","1px solid #eeeeee");
}
});
});
</script>
</form>