What am I doing wrong

I want to copy selected fields to another table with a button.
I have orders table . I want to copy selected fields to orders2 table with a button. My friend gived me a code but this code not working. Can you say what is wrong. Thanks.

$check_sql=“select * from orders2 "
.” where orderno=".{orderid}
." and part_no=".{part_no};
//echo $check_sql;
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found

{
$delete_sql=“DELETE from orders2 "
.” where orderno=".{orderid}
." and part_no=".{part_no};
sc_exec_sql($delete_sql);
}

$insert_sql=“INSERT INTO orders2 (order2id, orderno, part_no, description, qty, each_net, total_net, delivery, note, comission, price_each, price_total) "
.” VALUES (’".{orderid}."’,’".{orderno}."’,’".{part_no}."’,’".{description}."’,’".{qty}."’,’".{each_net}."’,’".{total_net}."’,’".{delivery}."’,’".{note}."’,’"
.{comission}."’,’".{price_each}."’,’".{price_total}."’)";
sc_exec_sql($insert_sql);

Enable debugger and show us the debug messsages

(pdo-mysql): select * from orders2 where orderno= and part_no=1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘and part_no=’ at line 1

ADOConnection._Execute(select * from orders2 where orderno= and part_no=, false) % line 1149, file: [adodb.inc.php](file:///C:/Program%20Files/NetMake/v9-php73/wwwroot/scriptcase/prod/third/adodb/adodb.inc.php) ADOConnection.Execute(select * from orders2 where orderno= and part_no=) % line 5348, file: [form_orders_apl.php](file:///C:/Program%20Files/NetMake/v9-php73/wwwroot/scriptcase/app/seapart2/form_orders/form_orders_apl.php) form_orders_apl.scajaxbutton_Hesapla_onClick() % line 1616, file: [form_orders_apl.php](file:///C:/Program%20Files/NetMake/v9-php73/wwwroot/scriptcase/app/seapart2/form_orders/form_orders_apl.php) form_orders_apl.controle() % line 2405, file: [index.php](file:///C:/Program%20Files/NetMake/v9-php73/wwwroot/scriptcase/app/seapart2/form_orders/index.php) ajax_form_orders_event_scajaxbutton_hesapla_onclick(, , , , , , , , , , 3510, undefined) % line 122, file: [form_orders_sajax.php](file:///C:/Program%20Files/NetMake/v9-php73/wwwroot/scriptcase/app/seapart2/form_orders/form_orders_sajax.php)

(pdo-mysql): INSERT INTO orders2 (order2id, orderno, part_no, description, qty, each_net, total_net, delivery, note, comission, price_each, price_total) VALUES (’’,’’,’’,’’,’’,’’,’’,’’,’’,’’,’’,’’)

i changed the code now working but if i put the button 2 times same records coming 2 times,
how can i block same record inserting to new table. Thanks

$insert_sql=“INSERT INTO orders2 (orderno, part_no, description, qty, each_net, total_net, delivery, note, comission, price_each, price_total)
SELECT orderno, part_no, description, qty, each_net, total_net, delivery, note, comission, price_each, price_total FROM orders ORDER BY orderno”;
sc_exec_sql($insert_sql);

If you want to prevent the same record to be inserted multiple times into table order2 , make sure that in table order2 a proper primary key is defined, in order to avoid record duplicates
I presume orderno is a good candidate for a primary key.

i have to run this code but there is a problem. What is wrong in this code, can you help me? Thanks

I did a primary key, but page gives an error

Hata
Veritabanına erişilirken hata oluştu:
Duplicate entry ‘30066’ for key ‘PRIMARY’
INSERT INTO orders2 (order2id, orderno, part_no, description, qty, each_net, total_net, delivery, note, comission, price_each, price_total) SELECT orderid, orderno, part_no, description, qty, each_net, total_net, delivery, note, comission, price_each, price_total FROM orders ORDER BY orderno

Instead of INSERT INTO look at REPLACE INTO