Please tell me there is a code that makes a copy of the fields in the table.

<?php $date = date("dmY G:i"); $servername = "localhost"; $database = "*"; $username = "*"; $password = "*"; $conn = mysqli_connect($servername, $username, $password, $database); mysqli_set_charset($conn, 'utf8'); $sql = "insert into order_products( name, price, id_products, amount, image) select name, price, id_products, amount, image from order_products where id_order=1"; mysqli_query($conn, $sql); $id = mysqli_insert_id($conn); mysqli_close($conn); header("Location: /"); ?> 

There is also an id_order column, in this field you need to write your value. Tell me how to do it. Thank.

  • select name, price, id_products, amount, image, 42 from ... ? - u_mulder pm
  • @u_mulder as always came to the rescue) Thank you very much. - Vladislav Samokhin

1 answer 1

Add the desired value to the list of select fields:

 $sql = "insert into order_products( name, price, id_products, amount, image, id_order) select name, price, id_products, amount, image, 42 from order_products where id_order=1"; 

Here, the order ID is 42 and the id_order field is added to the insert part.