我有一个表格可以改变名为"发票"的sql表。我想弹出一个bootstrap模式,它将改变一个名为" customers"的sql表。现在,唯一能够妥善保存的是客户名称...我错过了什么吗?这是我到目前为止的代码......
主页:
type mismatch; found : List[String] required: org.json4s.JValue (which expands to) org.json4s.JsonAST.JValue
表单保存代码:
<!-- Modal Add Customer -->
<div class="modal fade" id="addNewCustomer" tabindex="-1" role="dialog" aria-labelledby="addNewCustomerLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add New Customer</h4>
</div>
<div class="modal-body">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="add_customer_form" method="post" class="form-horizontal myaccount" role="form">
<div class="form-group col-lg-7">
<label for="customer_Name_modal">Customer Name (Last Name, First Name)</label>
<input type="text" class="form-control" id="customer_Name_modal" name="customer_Name_modal" placeholder="Last Name, First Name">
<span class="help-block"></span>
</div>
<div class="form-group col-lg-7">
<label for="customer_Phone_modal">Phone Number (555-555-5555)</label>
<input type="text" class="form-control" id="customer_Phone_modal" name="customer_Phone_modal" placeholder="555-555-5555">
<span class="help-block"></span>
</div>
<div class="form-group col-lg-7">
<label for="customer_Email_modal">Email (johndoe@gmail.com)</label>
<input type="text" class="form-control" id="customer_Email_modal" name="customer_Email_modal" placeholder="john@doe.com">
<span class="help-block"></span>
</div>
<div class="form-group col-lg-7">
<label for="customer_Address1_modal">Address Line 1 </label>
<input type="text" class="form-control" id="customer_Address1_modal" name="customer_Address1_modal" placeholder="">
<span class="help-block"></span>
</div>
<div class="form-group col-lg-7">
<label for="customer_Address2_modal">Address Line 2 </label>
<input type="text" class="form-control" id="customer_Address2_modal" name="customer_Address2_modal" placeholder="">
<span class="help-block"></span>
</div>
<input type="hidden" id="current_element_id">
</form>
</div>
<div class="modal-footer">
<button type="button" id="add_new_customer_btn" class="btn btn-primary" data-loading-text="Saving Customer...">Save changes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Sql代码:
var save_new_customer = function(){
$('#add_new_customer_btn').button('loading');
data = {
customerName : $('#customer_Name_modal').val(),
customerPhone : $('#customer_Phone_modal').val(),
customerEmail : $('#customer_Email_modal').val(),
customerAddress1 : $('#customer_Address1_modal').val(),
customerAddress2 : $('#customer_Address2_modal').val(),
}
$.ajax({
url: "ajax.php",
dataType: "json",
method: 'post',
data: {
data : data,
type: 'saveNewCustomer'
},
success: function(result){
if( (typeof result.success !== "undefined") && result.success ){
$("html, body").animate({ scrollTop: 0 }, "slow");
$('#add_new_customer_btn').button('reset');
$('#addNewCustomer').modal('show');
element_id = $('#current_element_id').val();
$('#customerName_'+element_id).val($('#customer_Name_modal').val());
$('#phone_'+element_id).val( $('#customer_Email_modal').val() );
$('#email_'+element_id).val($('#customer_Phone_modal').val());
$('#addressLine1_'+element_id).val($('#customer_Address1_modal').val());
$('#addressLine2_'+element_id).val($('#customer_Address2_modal').val());
$('#add_customer_form')[0].reset();
$('#add_customer_form').find("div.form-group").removeClass('has-success');
$('#message_h1').show();
message('success', CUSTOMER_ADD_SUCCESS);
}else{
message('fail', CUSTOMER_ADD_FAIL);
}
}
});
}
答案 0 :(得分:2)
您在PHP中使用了错误的密钥
您正在拨打这些密钥:
$customerName = mysqli_real_escape_string( $db->con, trim( $data['customerName'] ) );
$customerPhone = mysqli_real_escape_string( $db->con, trim( $data['phone'] ) );
$customerEmail = mysqli_real_escape_string( $db->con, trim( $data['email'] ) );
$customerAddress1 = mysqli_real_escape_string( $db->con, trim( $data['addressLine1'] ) );
$customerAddress2 = mysqli_real_escape_string( $db->con, trim( $data['addressLine2'] ) );
但你应该打电话:
$customerName = mysqli_real_escape_string( $db->con, trim( $data['customerName'] ) );
$customerPhone = mysqli_real_escape_string( $db->con, trim( $data['customerPhone'] ) );
$customerEmail = mysqli_real_escape_string( $db->con, trim( $data['customerEmail'] ) );
$customerAddress1 = mysqli_real_escape_string( $db->con, trim( $data['customerAddress1'] ) );
$customerAddress2 = mysqli_real_escape_string( $db->con, trim( $data['customerAddress2'] ) );
要解决此问题,只需在SQL代码中复制并粘贴(替换)变量赋值。