I have used prepared statement to insert an order into an orders table but now I want to insert the order items into the order items table based on the last ID inserted in t
You can try $stmt->insert_id to get inserted id
$stmt->insert_id
If you're using PDO, it's PDO::lastInsertId(). So if your database handle is called $link:
$link
$order_id = $link->lastInsertId();
If you're using MySQLi, it's mysqli::$insert_id or mysqli_insert_id():
mysqli_insert_id()
$order_id = $link->insert_id;