Storing customers' orders
My question is simple: is this secure?


It's safe from SQL injection attacks.


  If many people buy at the same time can I have problems?


Since you insert the order and the cart contents in a transaction, the table will be locked until you have inserted everything, preventing other users from placing their orders. So the transaction can become a bottleneck. However, this is the right way of doing it, if it's important for you to avoid partial orders.


  Is there a possibility of a product being directed to the wrong customer? 


One thing is not clear, what happens if the first query fails. You didn't check for errors, though I would guess that in that case you won't get a meaningful insert ID (would have to check the docs). In any case, you should check for errors after all insert operations and handle gracefully.

Other than that, the transaction guarantees that order IDs won't get mixed up. Even without the transaction, probably it wouldn't happen, but I'd have to dig into the docs for that.


  Can I trust in this method?


Yes, keeping in mind the potential bottleneck and other considerations above.