当我尝试将其发送到数据库时,出现错误。 #1054 - Unknown column 'receipt_-6ren">
gpt4 book ai didi

php - 将从数据库检索到的表单值再次插入 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-29 20:01:19 25 4
gpt4 key购买 nike

我有一个只读文本框,它从数据库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

最佳答案

我已经解决了上述问题。

编辑后的代码如下:

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

关于php - 将从数据库检索到的表单值再次插入 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40528840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com