I'm trying to copy products from a cart (from cart_product) to the order_product table
Can this query work this way by preparing the the column name to become a value of the order_id
// Create the order
$order_id = $this->order->store();
// Copy products from cart and assign them to the order
$req = "INSERT INTO order_product (order_id, product_id)
SELECT :order_id, product_id,
FROM cart_product, cart
WHERE cart.user_id = :id";
$bind = array(
"id" => $_SESSION['id'],
"order_id" => $order_id
);
return $this->Sql($req);
I'm using a micro framework, where the Sql function came.
I want the query to become something like this
INSERT INTO order_product (order_id, product_id)
SELECT 3, product_id,
FROM cart_product, cart
WHERE cart.user_id = 2