vendredi 8 mai 2015

Getting string results to INSERT into database from foreach loop

I am creating a checkout system and I am trying to figure out how I am going to insert the string from the results of my foreach loop that displays which products were chosen, the quantity, and and pertinent data about them.

The way I have the shipping information in place is I validate it and if it passes, I allow it to be inserted once the order is placed. Like this:

if(Input::exists()) {
        $validate = new Validate();
        $validation = $validate->check($_POST, array(
            'fullname' => array(
                'required' => true,
                'min' => 2,
                'max' => 50
            )

if($validation->passed()) {
            if(isset($_POST['create'])){ 
                $fullname = trim( $_POST['customer_name'] );

<div class="field">
                                        <label class="paddingleft" for="fullname">Full Name</label>
                                    <div class="center"><input type="text"  class="biginputbarinline" name="fullname" value="<?php echo escape(Input::get('firstname')); ?>" required></div>
                                    </div>

I am wanting to INSERT all of the data on my page at once and not do seperate INSERT submissions. I have the shipping info, payment info and Order confirmation all on the same page. I will not be storing the payment info in my database. So that is irrelevant to this question. The Order confirmation is where the order will be displayed and I want that info to send in to my database with my shipping info.

The part I am really confused with is how to INSERT the actual string this foreach loop displays. This is how I have the Order confirmation section as of now..

<div class="checkoutconfirmationcontainer">
                                            <?php foreach($_SESSION['shopping_cart'] as $id => $product) {
                                                    $product_id = $product['product_id'];
                                        ?>
                                        <span class="tealmedium"><?php echo $product['quantity'] . " - "  . $products[$product_id]['name'] . $message; ?></span><br><br><br>


                                            <div class="floatleft"><div class="smallerimgcontainer">
                                                    <?php
                                                        $result = mysqli_query($con,"SELECT * FROM products");
                                                        if($row = mysqli_fetch_array($result)) {
                                                            $products[$row['product_id']] = $row;

                                                        if($row['image'] == ""){
                                                                echo "<img class='sizedimg' src='/productpics/coming_soon.png' alt='Coming Soon'>";
                                                        } else {
                                                                echo "<img class='sizedimg' src='/productpics/".$row['img']."' alt='Product Picture'>";
                                                        }
                                                        echo "<br><br><br><br>";
                                                        }
                                                    ?>
                                            </div></div>
                                            <div class="checkoutitemsummary">
                                                <?php echo "<a href='./viewProduct.php?view_product=$id'>" . $product['name'];?><?php echo $products[$product_id]['name']; ?> </a>
                                                    <p><span class="redprice"><?php echo '$' . $products[$product_id]['price'] . "<br />"; }?></span></p>
                                            </div>

How could I get the foreach loop produced string to be inserted into my database?

Aucun commentaire:

Enregistrer un commentaire