douhuan1497 2019-08-15 13:47
浏览 86

联系表单不向我的数据库发布值

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)