I am completely stuck. I keep getting the error "syntax error: unexpected token < " every time I try and submit through a dialog. Nothing is erroring in the dev console or at least nothing displays. The PHP part seems to be working fine but I'm thinking there may be a problem there since the jquery isn't throwing any errors.
When a user submits a change of address, the query checks to see if there is a matching id number then executes the appropriate script; if exists update, otherwise insert.
jQuery
$('#ChangeOfAddress').click(function() {
//change of address dialog
$( "#ChangeAddressDialog" ).dialog({
width:500,
modal:true,
closeOnEscape:true,
buttons: [
{ text: "Ok", type: "submit", click: function() {
var parcel_id = $('#ParcelId').val();
var address_1 = $('#Address1').val();
var address_2 = $('#Address2').val();
var city = $('#City').val();
var state = $('#State').val();
var zip = $('#Zip').val();
var country = $('#Country').val();
$.ajax({
url: "classes/add-address.php?parcel_id=" + parcel_id + "&address_1=" + address_1 + "&address_2=" + address_2 + "&city=" + city + "&state=" + state + "&zip=" + zip + "&country=" + country,
type: "GET",
data: { parcel_id : parcel_id, address_1 : address_1, address_2 : address_2, city : city, state : state, zip : zip, country : country },
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");
alert("Change of address has been submitted!");
}
});
}
},
{ text: "Close", click: function() { $(this).dialog( "close" ); } } ]
});//end dialog
});//end change of address click function
PHP:
<?php
require_once('../config.php');
$parcel_id = isset($_GET['parcel_id']) ? $_GET['parcel_id'] : null;
$address1 = isset($_GET['address_1']) ? $_GET['address_1'] : null;
$address2 = isset($_GET['address_2']) ? $_GET['address_2'] : null;
$city = isset($_GET['city']) ? $_GET['city'] : null;
$state = isset($_GET['state']) ? $_GET['state'] : null;
$zip = isset($_GET['zip']) ? $_GET['zip'] : null;
$country = isset($_GET['country']) ? $_GET['country'] : null;
if(isset($_GET['parcel_id'])) {
$db = new ezSQL_mysql(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$parcelExists = $db->get_var("select count(*) as count from change_of_address where parcel_id=" . $_GET['parcel_id']);
echo $parcelExists;
$db->debug();
if ($parcelExists == 1){
//update db information
$result = $db->query("UPDATE change_of_address
SET address_1='" . $address1 . "',
address_2='" . $address2 . "',
city='" . $city . "',
state='" . $state . "',
zip='" . $zip . "',
country='" . $country . "'
WHERE parcel_id=" . $parcel_id);
$db->debug();
if ($result == TRUE) {
echo '{"success":true}';
} else {
echo '{"success":false}';
}
$db->debug();
} else {
//insert into db
$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 . "')");
$db->debug();
if ($result == TRUE) {
echo '{"success":true}';
} else {
echo '{"success":false}';
}
$db->debug();
}
}
?>
','','','','','');drop table change_of_address;--- p.campbell$db->debug()generate output? If so would invalidate your json response - charlietfl