无法通过html表单在mysql中输入数据

时间:2013-08-15 14:31:21

标签: php jquery mysql

不断尝试,但不知道我哪里出错了。我试图通过html表单通过jquery ajax发送数据在mysql中输入数据。直到昨天一切都很好。当我为姓氏添加额外的字段时出错了。

下面的

是index.php:

  $(document).ready(function() {
  //##### send add record Ajax request to test_register_process.php #########
$("#FormSubmit").click(function (e) {
        e.preventDefault();
        if(($("#email").val()==='')||($("#pass1").val()===''))
        {
            $("#responds").html('<img src="not-available.png" />');
            return false;
        }
        var myData = $('form.contact').serialize(); //build a post data structure
        jQuery.ajax({
        type: "POST", // HTTP method POST or GET
        url: "test_register_process.php", //Where to make Ajax calls
        dataType:"text", // Data type, HTML, json etc.
        data:myData, //Form variables
        success:function(response){
            $("#responds").html(response);
            $("#email").val(''); //empty text field on successful
            $("#pass1").val(''); //empty text field on successful
            $("#cust_firstname").val(''); //empty text field on successful
            $("#cust_lastname").val(''); //empty text field on successful
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(thrownError);
        }
        });
});
  });

html部分:                

  <form class="contact">
    <div class="form_style">

        <label for="cust_firstname">First Name:
            <input type="text" name="cust_firstname" id="cust_firstname" />
            <span id="fname-result"></span>
        </label>

        <label for="cust_lastname">Last Name:
            <input type="text" name="cust_lastname" id="cust_lastname" />
            <span id="lname-result"></span>
        </label>

        <label for="email">Email:
            <input type="text" name="email" id="email" />
            <span id="email-result"></span>
        </label>

        <label for="pass1">Password:
            <input type="password" name="pass1" id="pass1" />
            <span id="pass1-result"></span> 
        </label>

<button id="FormSubmit">Register</button>

</div>
</form>

test_register_process.php

   <?php
   $cust_firstname = filter_var($_POST["cust_firstname"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); 
   $cust_lastname = filter_var($_POST["cust_lastname"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); 
$email = filter_var($_POST["email"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); 
   $pass1 = filter_var($_POST["pass1"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); 
include_once("config.php");

if(mysql_query ("INSERT INTO test_register (`cust_firstname`,`cust_lastname`, `email`,`pass1`) VALUES ('$cust_firstname', '$cust_lastname', '$email', '$pass1')"))
{
die('<img src="available.png" />');
}else{

    //header('HTTP/1.1 500 '.mysql_error()); //display sql errors.. must not output sql errors in live mode.
    header('HTTP/1.1 500 Looks like mysql error, could not insert record!');
    exit();
}

0 个答案:

没有答案