我不知道我在做什麼錯誤。我有一個對話框,用戶可以輸入地址,然後單擊確定,它會將輸入的信息插入數據庫。我不斷收到「意外的輸入結束」錯誤或「意外標記」錯誤。我有一種感覺,它與jquery ajax函數中的serialize屬性有關,但我不確定。輸入錯誤意外結束,再次
我不知道如何回顯變量,看看他們是否從字段或sql語句獲取數據。我試了很多,它或者崩潰了頁面,或者它給了我相同的「意外」錯誤。
請幫忙! :(
jQuery代碼:
$('#ChangeOfAddress').click(function() {
//change of address dialog
$("#ChangeAddressDialog").dialog({
width:500,
modal:true,
closeOnEscape:true,
buttons: [
{ text: "Ok", type: "submit", click: function() {
$.ajax({
url: "classes/add-address.php",
type: "POST",
data: $("#main_form").serialize(),
dataType: 'json',
error: function(SMLHttpRequest, textStatus, errorThrown){
alert("An error has occurred making the request: " + errorThrown)
},
success: function(result){
//do stuff here on success such as modal info
//$("#main_form").submit();
$(this).dialog("close");
}
})
}
},
{ text: "Close", click: function() { $(this).dialog("close"); } } ]
});//end dialog
});
PHP頁面:(EZ SQL INSERT返回一個布爾值)
<?php
require_once('../config.php');
$sqlCheck = '';
$parcel_id = isset($_POST['ParcelId']) ? $_POST['ParcelId'] : null;
$address1 = isset($_POST['Address1']) ? $_POST['Address1'] : null;
$address2 = isset($_POST['Address2']) ? $_POST['Address2'] : null;
$city = isset($_POST['City']) ? $_POST['City'] : null;
$state = isset($_POST['State']) ? $_POST['State'] : null;
$zip = isset($_POST['Zip']) ? $_POST['Zip'] : null;
$country = isset($_POST['Country']) ? $_POST['Country'] : null;
$db = new ezSQL_mysql(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$result = $db->query("INSERT INTO change_of_address (parcel_id, address_1, address_2, City, State, Zip, Country) VALUES ('" . $parcel_id . "','" . $address1 . "','" . $address2 . "','" . $city . "','" . $state . "','" . $zip . "','" . $country . "')");
if ($result == 1) {
echo true;
} else {
echo false;
}
//$sqlCheck = "INSERT INTO change_of_address (parcel_id, address_1, address_2, City, State, Zip, Country) VALUES ('" . $parcel_id . "','" . $address1 . "','" . $address2 . "','" . $city . "','" . $state . "','" . $zip . "','" . $country . "')";
?>
我嘗試添加以下,但它並不會返回任何錯誤:
error_reporting(E_ALL);
ini_set('display_errors', 'On');
你在哪裏得到的錯誤?在服務器上?或者在瀏覽器控制檯上?它是否說出哪些行號出錯? – philtune 2014-12-03 17:40:12
它什麼也沒說。只是一個警告,說「意外結束輸入」錯誤或「意外的令牌」 – maryjane 2014-12-03 17:45:53