我有一个只读文本框,它从数据库sales
表中检索最大收据号为否。
<input name="txtReceiptNo" type="text" id="txtReceiptNo" size="10" value="<?php
$receiptNo = mysqli_fetch_row(mysqli_query($connection,"SELECT max(sales_id)+1 FROM sales")); echo $receiptNo[0];?>" readonly />
当我尝试将其发送到数据库时,会出错。
#1054 - Unknown column 'receipt_no' in 'field list'
(是的,我知道这是不正确的,但我怎么能纠正这个?)
SQL查询:
INSERT INTO sales(cus_id,item_id,stock_id,receipt_no,qty,unit_price,discount,amount,user_id,purchase_id)
SELECT C.cus_id, I.item_id, S.stock_id, receipt_no='$receipt_no',ST.qty, ST.unit_price, ST.discount, ST.amount, U.id, P.purchase_id
FROM customers C, items I, stock S, sales_temp ST, users U, purchase_items P
WHERE ST.staff='$user' AND
C.customer_name='$customer' AND
I.item_name=ST.item_name AND
S.stock_code=ST.stock_code AND
ST.purchase_id=P.purchase_id
INSERT INTO sales(cus_id,item_id,stock_id,receipt_no,qty,unit_price,discount,amount,user_id,purchase_id)
SELECT C.cus_id, I.item_id, S.stock_id, receipt_no='$receiptNo',ST.qty, ST.unit_price, ST.discount, ST.amount, U.id, P.purchase_id
FROM customers C, items I, stock S, sales_temp ST, users U, purchase_items P
WHERE ST.staff='$user' AND
C.customer_name='$customer' AND
I.item_name=ST.item_name AND
S.stock_code=ST.stock_code AND
ST.purchase_id=P.purchase_id
答案 0 :(得分:0)
我已经解决了上述问题。
编辑后的代码如下:
INSERT INTO sales(cus_id,item_id,stock_id,receipt_no,qty,unit_price,amount,user_id,purchase_id)
SELECT C.cus_id, I.item_id, S.stock_id, $receipt_no, ST.qty, ST.unit_price, ST.amount, U.id, P.purchase_id
FROM customers C, items I, stock S, sales_temp ST, users U, purchase_items P
WHERE ST.staff='$user'
AND C.customer_name='$customer'
AND I.item_name=ST.item_name
AND S.stock_code=ST.stock_code
AND ST.purchase_id=P.purchase_id