Skip to content Skip to sidebar Skip to footer

Php - How Can I Insert Multiple Items From A Shopping Cart Into The Database?

I'd like to apologize in advance if this question has been asked before. I've been surfing this website for a couple of hours trying to find the answer I'm looking for but no luck.

Solution 1:

Your example doesn't show any insert statements at all... You should lookup and learn INSERT INTO (http://www.w3schools.com/php/php_mysql_insert.asp). Then you will end up have a foreach loop... the basic code will end up looking something like this:

foreach ($itemsas$item) {
    $sql= 'INSERTINTO `order_history` (`productid`, `productqty`)'
        . ' VALUES ($item['product_id'], $item['product_qty']);
    mysql_query($sql);
}

Of course I'm leaving out error checking and all kinds of extra fields you will want to populate... but you get the idea. Good luck!

Post a Comment for "Php - How Can I Insert Multiple Items From A Shopping Cart Into The Database?"