Php 使引导模式使用单独的表单/sql表
我有一个表单,它修改了一个名为“invoices”的sql表。我想弹出一个引导模式,它将改变一个名为“customers”的sql表。现在,唯一正确保存的是客户名称。。。我错过什么了吗?这是我到目前为止的代码 主页:Php 使引导模式使用单独的表单/sql表,php,jquery,mysql,twitter-bootstrap,Php,Jquery,Mysql,Twitter Bootstrap,我有一个表单,它修改了一个名为“invoices”的sql表。我想弹出一个引导模式,它将改变一个名为“customers”的sql表。现在,唯一正确保存的是客户名称。。。我错过什么了吗?这是我到目前为止的代码 主页: <!-- Modal Add Customer --> <div class="modal fade" id="addNewCustomer" tabindex="-1" role="dialog" aria-labelledby="addNewCust
<!-- 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代码:
if(isset($_POST['type']) && $_POST['type'] == 'saveNewCustomer' ){
$res = array();
$res['success'] = false;
if(!isset($_POST['data']) || empty($_POST['data'])){
echo json_encode($res);exit;
}
$data = $_POST['data'];
$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'] ) );
$uuid = uniqid();
$result['operation'] = 'insert';
$query = "INSERT INTO customers (id, customerName, phone, email, addressLine1, addressLine2, uuid)
VALUES (NULL, '$customerName', '$customerPhone', '$customerEmail', '$customerAddress1', '$customerAddress2', '$uuid');";
if(mysqli_query($db->con, $query)){
mysqli_close($db->con);
$res['success'] = true;
}
echo json_encode($res);exit;
}
您在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代码中的变量赋值。我在你发帖前2秒就发现了这个问题,哈哈。这已经让我发疯一个小时了!非常感谢。
$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'] ) );