그래서 jquery 아약스의 직렬화 부분에 문제가 있다고 생각합니다. 그것은 어떤 정보도 데이터베이스에 넣지 않고 왜 그럴지 모릅니다! 웹 페이지의 입력 컨트롤에있는 변수는 PHP 처리 페이지로 전달되지 않습니다. 나는 여기서 무엇을 잘못하고 있니? 이 사람들과 함께 여기에 도움이 필요해! 이것은 나에게 아주 새로운 것입니다.데이터가 데이터베이스에 삽입되어 있지 않습니다.
웹 페이지 :
<form name="main_form" id="main_form" method="post">
<div id="ChangeAddressDialog" title="Change of Address">
<p>Mailing Address: <input type="text" id="Address1" name="Address1" /></p>
<p>Mailing Address 2: <input type="text" id="Address2" name="Address2" /></p>
<p>City: <input type="text" id="City" name="City" /></p>
<p>State: <input type="text" id="State" name="State" maxlength="2" /></p>
<p>Zip Code: <input type="text" id="Zip" id="Zip" maxlength="10" /></p>
<p>Country: <input type="text" id="County" name="Country" /></p>
<input type="hidden" id="change_of_address_form" name="change_of_address_form" />
</div>
</form>
$('#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 처리 페이지 :
<?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 '{"success":true}';
} else {
echo '{"success":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 . "')";
//echo json_encode($sqlCheck);
?>
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 이것은 ** 무섭게 불안하다. 모든 사용자 매개 변수가 [제대로 이스케이프 처리]되어 있는지 확인해야합니다 (http://bobby-tables.com/php). 응용 프로그램이 손상 될 위험이 있습니다. 가능하면 준비된 문장과 자리 표시자를 사용하여 그 종류의 오류에 노출되지 않도록하십시오. ['ezSQL_mysql'] (http://docs.phpvms.net/internals/d5/d95/classez_s_q_l__mysql.html)에는 긴급하게 ** 사용해야하는 '이스케이프 (escape)'기능이 있습니다. – tadman
@JonathanKuhn 감사합니다. 나는 그것을 form 태그에 추가했지만 db :/ – maryjane
@tadman에 내부적으로 삽입하지는 않았다. 기능을 얻은 다음 나중에 보안 문제를 해결해야합니다. 사장님은 그걸 가지고 놀아 주길 원합니다. – maryjane