php - foreach loop results to INSERT into database -


i have 3 different div's contain checkout information.

  1. shipping info
  2. billing info
  3. order confirmation

the shipping information , billing information obtained customer entering information in manually, order confirmation, contains ordering, quantity, , pertinent information order resides there. information obtained foreach loop have in place displays information based on product's id.

i trying figure out how going insert string displays foreach loop database. have order report page want display ordered.

for shipping information, validate , send query in information. this...

<?php 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> 

the part confused how insert actual string foreach loop displays. if result of foreach loop was:

2 balls

4 shoes.

i want information send in query.

this how have order confirmation section of now..

<div class="checkoutconfirmationcontainer"> <?php foreach($_session['shopping_cart'] $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 * 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 can results of foreach loop inserted database query?

shopping cart

<tr>                                 <th class="cartth">name</th>                                 <th class="cartth">price</th>                                 <th class="cartth">category</th>                                 <th class="cartth">quantity</th>                             </tr> <?php                                                        $base_price = 0;                         foreach($_session['shopping_cart'] $id => $product) {                                     $product_id = $product['product_id'];                                     $base_price += $products[$product_id]['price'] * $product['quantity'];                                     $shipping_price += $products[$product_id]['shippingprice'] * $product['quantity']; ?>                                 <tr>                                         <td class="carttd"><?php echo "<a href='./viewproduct.php?view_product=$id'>" . $product['name'];?><?php echo $products[$product_id]['name']; ?> </a>                                         </td>                                         <td class="carttd"><?php echo '$' . $products[$product_id]['price']; ?></td>                                          <td class="carttd"><?php echo $products[$product_id]['category']; ?></td>                                         <td class="carttd">                                         <?php echo "<input type='text' name='quantity[$product_id]'  value='" . $product['quantity'] . "' />"; ?> </td>                                                                          </tr> <?php                                 } 

javascript/jquery produces div transition:

$('.checkoutmenu>li').on('click',function(e){     $('.checkoutprocess>.'+ e.target.classlist[0]).show().siblings().hide(); });   <script>                     $('.paymentinfocontainer').hide(); $('.confirmationinfocontainer').hide(); </script> <script> $('#button2').click(function () {     $(".checkoutprocess > div").hide();     $('.paymentinfocontainer').show("slow"); }); </script> <script> $('#button3 ').click(function () {     $(".checkoutprocess > div").hide();     $('.confirmationinfocontainer').show("slow"); }); </script>  <script> /* $('#button1').click(function () {     $(".checkoutprocess > div").hide();     $('.shippinginfocontainer').show("slow"); }); </script> <script> $('#button2 ').click(function () {     $(".checkoutprocess > div").hide();     $('.paymentinfocontainer').show("slow"); }); </script> <script> $('#button3 ').click(function () {     $(".checkoutprocess > div").hide();     $('.confirmationinfocontainer').show("slow"); }); */ </script> 

ok, when clicked on "3. order confirmation", got following html:

<div class="confirmationinfocontainer" style="display: block;">     <span class="summarytitle"><p>order confirmation</p></span>     <br>     <div class="floatrightinline">         <div class="confirmshippinginfo">             <p>shipping to:</p>             <p></p>             <p></p>             <p></p>             <p></p>         </div>     </div>     <div class="checkoutconfirmationcontainer">         <div name="product_id"></div>         <span class="tealmedium">1 - lakers hat</span>         <br>         <br>         <br>         <div class="floatleft">             <div class="smallerimgcontainer">                 <img alt="coming soon" src="/productpics/coming_soon.png" class="sizedimg">                 <br>                 <br>                 <br>                 <br>             </div>         </div>         <div class="checkoutitemsummary">             <a href="./viewproduct.php?view_product=11">lakers hat </a>             <p><span class="redprice">$25<br></span></p>         </div>         <input type="hidden" value="405bb6b2b562b4f00dac620d3f68620f" name="token">         <input type="submit" value="place order" class="widebutton">         <br>     </div> </div> 

so see you're making use of hidden field. when users clicks "place order" button, want details passed along. can add these details form via hidden field. so:

<div class="checkoutconfirmationcontainer"> <?php foreach($_session['shopping_cart'] $id => $product) {      $product_id = $product['product_id']; ?>      <input type="hidden" name="product_quantity[<?php echo $id; ?>]" value="<?php echo $product['quantity']; ?>" />      <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 * 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']} {$products[$product_id]['name']}</a>"; ?>           <p><span class="redprice"><?php echo '${$products[$product_id]['price']}<br />"; }?></span></p>      </div>      <input type="hidden" name="token" value="405bb6b2b562b4f00dac620d3f68620f">      <input class="widebutton" type="submit" value="place order">      <br /> </div> 

looking on this, see no <form> this. suspect jquery handling somewhere else. fix may not read if jquery or app not for, or not hook onto hidden field. if framework you're using or catalog you're modifying, check support. have lot more work ahead of you.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -