我想在复制列的同时插入数据。
$db->query("INSERT INTO transactions
(order_id,cart_id,full_name,email,phone,street1,street2,
city,state,zip_code,country,landmark,sub_total,tax,grand_total,
description,txn_type,paid,customer_id,items)
VALUES
('$order_id','$cart_id','$full_name','$email','$phone','$street1','$street2',
'$city','$state','$zip_code','$country','$landmark','$sub_total','$tax',
'$grand_total','$description','$txn_type','$paid','$customer_id', items
FROM cart WHERE id ='$cart_id')
");
在上面的代码中,我在复制的同时插入了所有的值
"items from cart where id=$cart_id".
我做错了什么?
最佳答案
似乎你需要一个插入选择
insert into transactions
(order_id,cart_id,full_name,email,phone,street1,street2,
city,state,zip_code,country,landmark,sub_total,tax,grand_total,
description,txn_type,paid,customer_id,items)
SELECT
'$order_id','$cart_id','$full_name','$email','$phone','$street1','$street2',
'$city','$state','$zip_code','$country','$landmark','$sub_total','$tax',
'$grand_total','$description','$txn_type','$paid','$customer_id', items
FROM cart WHERE id ='$cart_id'
你不应该在 sql 中使用 php var 你有 sqlinjection 的风险..你应该看看你的 mysql 驱动程序以准备语句和绑定(bind)参数..
关于php - 如何在mysql中复制列时插入数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52138803/