这是我的能够插入的Jquery
$(function(){
$(document).on('click', '#addRefBtn', function(e){
var get_input = $('#qr_ref').val();
var get_po = $('#get_po').val();
location.reload();
$.ajax({
type: 'POST',
url: 'validate_qr.php',
data: {
qr_code:get_input,
po_ID: get_po
},
success: function(result){
// console.log(result);
},
error: function(result){
}
});
});
});
这是我在ajax中的网址,是由我要插入的查询组成的,而且我也想更新
$query = $conn->prepare("INSERT INTO product_sales (product_id, client_id, po_ID, unitPrice, sales_date, updated_date, invoiceTerminated, reference_no, status)
VALUES (:product_id, :client_id, :po_ID, :unitPrice, :sales_date, :updated_date, :invoiceTerminated, :reference_no, :status)");
$query->execute([
'product_id'=> $product_id,
'client_id'=> $client_id,
'po_ID'=> $po_ID,
'unitPrice'=> $etc_price,
'sales_date'=> $date,
'updated_date'=> $updated_date,
'invoiceTerminated'=> $invoiceTerminated,
'reference_no'=> $New_ref_no,
'status'=> $status
]);
$queryUpdate = $conn->prepare("UPDATE backup_sales t1
JOIN product t2 ON (t1.model_id = t2.model_id)
SET t1.status = '1',
t2.prod_status = '1'
WHERE t1.po_ID = ':po_ID'
AND t2.model_id = ':product_id'");
$queryUpdate->execute(['po_ID'=>$po_ID, 'product_id'=>$product_id]);
我的方法正确吗?我想念什么吗?请纠正我,谢谢。
答案 0 :(得分:1)
不要引用占位符,这会使它们成为字符串,而不是占位符。在您的UPDATE
的{{1}}子句中,
WHERE
应为:
WHERE t1.po_ID = ':po_ID' AND t2.model_id = ':product_id'
因此驱动程序可以将它们替换为值。这也应该引发错误,因为您尝试绑定2个值,但没有将其绑定到的占位符。