Checkout (page) backend
I see two obvious problems:


Your MySQLi queries are vulnerable to sql-injection since you are constructing the queries using string interpolation.  You should use properly parameterized queries with ? placeholders instead.
The business logic is heavily intertwined with the HTML generation.  You would be better off handling the input first (using PHP more like a programming language), writing the order to the database, then when the transaction has successfully completed, proceed to display the output (using PHP as a template language).