2016-08-20 4 views
-1

ショッピングカートの作成に問題があります。製品表のカート追加ボタンをクリックするとカートに表示されるように出力を設定するにはどうすればよいですか?PHPでセッションを使用してショッピングカートを作成する方法

//Product List 
<?php 

    $query = "SELECT * FROM products"; 
    $exec = mysqli_query($connection, $query); 

    while ($row = mysqli_fetch_array($exec)) { 
     $product_id = $row['product_id']; 
     $product_name = $row['product_name']; 
     $product_quantity = $row['quantity']; 
     $product_price = $row['sell_price']; 


    ?> 
     <tr> 
      <td class="text-center"><?php echo $product_id; ?></td> 
      <td><?php echo $product_name; ?></td> 
      <td><?php echo $product_price; ?></td> 
      <td><?php echo $product_quantity; ?></td> 
      <td class="text-center"> 
      <div class="btn-group"> 
       <a href="add_sales.php?action=add&product_id=<?php echo $product_id; ?>" class="btn btn-xs btn-info" data-toggle="tooltip" title="Select"> 
       <span class="fa fa-shopping-cart"></span> 
       </a> 
      </div> 
      </td> 
     </tr> 
     <?php } ?> 

アイテムの詳細パネル

if (isset($_GET['product_id'])) { 

     $prod_id = $_GET['product_id']; 

     $selectProd = "SELECT * FROM products WHERE product_id = $prod_id"; 
     $execProd = mysqli_query($connection, $selectProd); 

     while ($row = mysqli_fetch_array($execProd)) { 

     $prod_name = $row['product_name']; 
     $prod_price = $row['sell_price']; 
     $quantity = $row['quantity']; 
    ?> 


    <div class="panel-body"> 
     <div class="col-md-2"> 
     <div class="form-group"> 
     <label for="">Item ID</label> 
      <input type="text" class="form-control" value="<?php echo $prod_id; ?>" readonly> 
      </div> 
     </div> 

     <div class="col-md-7"> 
     <div class="form-group"> 
     <label for="">Item Name</label> 
      <input type="text" class="form-control" value="<?php echo $prod_name ?>" readonly> 
      </div> 
     </div> 

     <div class="col-md-4"> 
     <div class="form-group"> 
      <label for="">Unit Price</label> 
      <input type="text" class="form-control" value="<?php echo $prod_price; ?>" readonly id="unitPrice"> 
     </div> 
     </div> 

     <div class="col-md-5"> 
     <div class="form-group"> 
      <label for="">Available Qty</label> 
      <input type="text" class="form-control" value="<?php echo $quantity ?>" readonly> 
     </div> 
     </div> 

     <div class="col-md-4"> 
     <div class="form-group"> 
      <label for="">Sale Qty</label> 
      <input type="number" class="form-control" id="saleQty" name="saleQty"> 
     </div> 
     </div> 

     <div class="col-md-5"> 
     <div class="form-group"> 
      <label for="">Total Amount</label> 
      <input type="text" class="form-control" id="totalSale" name="saleTotal" readonly> 
     </div> 
     </div> 

     <div class="col-md-4"> 
     <div class="form-group"> 
      <input type="submit" value="Add to Cart" class="btn btn-info form-control" formnovalidate> 
     </div> 
     </div> 

カート

<!-- Start of Customer's Cart --> 
<div class="col-md-12"> 
    <div class="panel panel-default"> 
    <div class="panel-heading"> 
     <strong> 
     <span class="fa fa-shopping-cart"></span> 
     <span>Customer's Cart</span> 
     </strong> 
    </div> 
    <div class="panel-body"> 
    <table class="table table-hover"> 
     <thead> 
     <tr> 
      <th>Product ID</th> 
      <th>Product Name</th> 
      <th>Product Quantity</th> 
      <th>Product Amount</th> 
      <th>Total Amount</th> 
      <th>Remove</th> 
     </tr> 
     </thead> 
     <tbody> 

     <tr> 
      <td></td> 
     </tr> 


     </tbody> 
    </table> 
    </div> 
    </div> 
</div> 
<!-- End of Customer Cart --> 

Ordering Page Flow (GIF)

+0

あなたは私たちを提供することができます –

+0

完了。私は他のウェブサイトでチュートリアルを検索しましたが、自分のフローに一致するものを見つけることができません。 – Odie

答えて

0

あなたinput要素のどれもあなたがよときnameが(と思う)ので、属性を持っていません(フォームにGETメソッドがある場合)、またはリクエストボディパラメータ(POSTメソッド)が使用できず、オーダーを送信した誰かの行為を「キャッチ」できません。あなたがそれらを追加し、フォームの送信を処理した場合(たとえばisset($_POST['order'])上のINGのifによって、あなたはDBに順序をINSERTことができ、DBテーブルからカートをレンダリングします。また、SQLインジェクションを防ぐためにhttp://php.net/manual/en/mysqli.prepare.phpに見える。

関連する問題