• 07-04-2021, 00:12:03
    #1
    Merhaba arkadaşlar php ile bir e ticaret sistemi yaptım ve sepet sisteminde ürün fiyatlarını belirtmek için cookie kullandım, fakat cookie ile sepette toplam fiyatı belirtemiyorum aşağıya bakın anlıyacaksınız.
    Toplam fiyatta 450 yazıyor fakat ben üstteki ürünlerin toplamını oraya bastırmak istiyorum.


    [HTMLR]
     <form action="#">
    
                <div class="table-content table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th class="li-product-remove"></th>
                                <th class="li-product-thumbnail">resim</th>
                                <th class="cart-product-name">başlık</th>
                                <th class="li-product-price">ücret</th>
                                <th class="li-product-quantity">adet</th>
                                <th class="li-product-subtotal"> toplam fiyat</th>
                            </tr>
                        </thead>
                        <tbody>
    
                            <?php
    
                            foreach ($_COOKIE['sepet'] as $key => $value) {
    
    
                                $urunler=$baglanti->prepare("SELECT * FROM  urunler where urun_id=:urun_id  order by urun_sira ASC");
                                $urunler->execute(array(
                                  'urun_id'=>$key
    
    
                              ));
                                $urunlercek=$urunler->fetch(PDO::FETCH_ASSOC);
    
    
                                ?>
    
    
    
                                <tr>
                                    <td class="li-product-remove">  <a href="islem?sepetsil&id=<?php echo  $key ?>"><i class="fa fa-times"></i></a>    </td>
    
    
    
    
                                    <td class="li-product-thumbnail"><a href="#"><img style="width: 200px" src="Admin/resimler/urunler/<?php echo $urunlercek['urun_resim'] ?>" alt="Li's Product Image"></a></td>
                                    <td class="li-product-name"><a href="#"><?php echo $urunlercek['urun_baslik'] ?></a></td>
                                    <td class="li-product-price"><span class="amount"><?php echo $urunlercek['urun_fiyat'] ?>₺</span></td>
                                    <td class="quantity">
                                        <label>Adet</label>
    
                                            <input class="col-md-2" value="<?php echo $value ?>" class="cart-plus-minus-box" value="1" type="text" readonly>
    
    
                                    </td>
                                    <td class="product-subtotal"><span class="amount"><?php echo $_COOKIE['fiyat'.$key]; ?>₺</span></td>
                                </tr>
                                <?php
    
    
                                $sepettoplam=$value * $_COOKIE['fiyat'.$key];
    
    
                                $kdv=$sepettoplam * 18/100;
    
    
                                $geneltoplam=$sepettoplam + $kdv;
                                ?>
    
    
    
                            <?php } ?>
    
    
    
    
    
                        </tbody>
                    </table>
                </div>
    
                <div class="row">
                    <div class="col-md-5 ml-auto">
                        <div class="cart-page-total">
                            <h2>Toplam fiyat</h2>
                            <ul>
                                <li>Toplam fiyat <span><?php  echo $sepettoplam; ?>₺</span></li>
                                <li>Kdv <span><?php echo $kdv ?>₺</span></li>
                                <li>Genel toplam <span><?php echo $geneltoplam ?>₺</span></li>
                            </ul>
                            <a href="odeme/index">Alışverişi tamamla</a>
                        </div>
                    </div>
                </div>
            </form>
    [COLOR=#D9DAE9][FONT="Open Sans"][/FONT][/COLOR][/HTMLR][COLOR=#D9DAE9][FONT="Open Sans"][/FONT][/COLOR]
  • 07-04-2021, 00:24:34
    #2
    yardım yokmu ya
  • 07-04-2021, 01:20:19
    #3
    foreach($_COOKIE['sepet'] as$key=> $value) {
    Siz önce bu kodu nasıl hata vermeden çalıştırabildiğinizi açıklayın
  • 07-04-2021, 01:28:45
    #4
    Abdullahx adlı üyeden alıntı: mesajı görüntüle
    foreach($_COOKIE['sepet'] as$key=> $value) {
    Siz önce bu kodu nasıl hata vermeden çalıştırabildiğinizi açıklayın
    neden hata versinki
  • 07-04-2021, 01:34:03
    #5
    tasarimbey adlı üyeden alıntı: mesajı görüntüle
    neden hata versinki
    Cookie de array veri tutulmaz benim bildiğim, önce json_encode yapıp öyle saklayın çerezleri, sonra kullanacağınız zaman json_decode ile alıp yeniden array e çevirip öyle kullanın.
  • 07-04-2021, 01:39:44
    #6
    sorunu çözdüm.
  • 07-04-2021, 09:04:50
    #7
    Cookie ile bu işlemleri yapmayın , başınıza iş alırsınız.
  • 07-04-2021, 09:19:57
    #8
    Abdullahx adlı üyeden alıntı: mesajı görüntüle
    foreach($_COOKIE['sepet'] as$key=> $value) {
    Siz önce bu kodu nasıl hata vermeden çalıştırabildiğinizi açıklayın
    Bunu ben de düşündüm

    tasarimbey adlı üyeden alıntı: mesajı görüntüle
    sorunu çözdüm.
    Konuyu düzenleyin, belki gelecekte birilerini farketmeden yardım etmiş olursunuz

    FaTe adlı üyeden alıntı: mesajı görüntüle
    Cookie ile bu işlemleri yapmayın , başınıza iş alırsınız.
    Katılıyorum
  • 07-04-2021, 11:15:42
    #9
    Arkadaşlar aynı sorunu yaşayacaklar için söylüyorum bende böyle çalıştı .
    <?php require_once 'header.php' ?>
    <div class="Shopping-cart-area pt-60 pb-60">
        <div class="container">
            <div class="row">
                <div class="col-12">
    
    
                 <?php if ($_GET['durum']=="eklendi") { ?>
                   <b style="color: green">ürününüz başarıyla sepete eklendi</b>
               <?php     } ?>
               <form action="#">
    
                <div class="table-content table-responsive">
                    <table class="table">
    
                        <thead>
                            <tr>
                                <th class="li-product-remove">Sil</th>
                                <th class="li-product-thumbnail">resim</th>
                                <th class="cart-product-name">başlık</th>
                                <th class="li-product-price">ücret</th>
                                <th class="li-product-quantity">adet</th>
                                <th class="li-product-subtotal"> toplam fiyat</th>
                            </tr>
                        </thead>
                        <tbody>
    
                            <?php
    
                            foreach ($_COOKIE['sepet'] as $key => $value) {
    
    
                                $urunler=$baglanti->prepare("SELECT * FROM  urunler where urun_id=:urun_id  order by urun_sira ASC");
                                $urunler->execute(array(
                                  'urun_id'=>$key
    
    
                              ));
                                $urunlercek=$urunler->fetch(PDO::FETCH_ASSOC);
    
    
                                ?>
    
    
                                <tr>
                                    <td class="li-product-remove"><a href="islem?sepetsil&id=<?php echo  $key ?>">X</a></td>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
    
    
    
                                    <td class="li-product-thumbnail"><a href="#"><img style="width: 200px" src="Admin/resimler/urunler/<?php echo $urunlercek['urun_resim'] ?>" alt="Li's Product Image"></a></td>
                                    <td class="li-product-name"><a href="#"><?php echo $urunlercek['urun_baslik'] ?></a></td>
                                    <td class="li-product-price"><span class="amount"><?php echo $urunlercek['urun_fiyat'] ?>₺</span></td>
                                    <td class="quantity">
                                        <label>Adet</label>
    
                                            <input class="col-md-2" value="<?php echo $value ?>" class="cart-plus-minus-box" value="1" type="text" readonly>
    
    
                                    </td>
                                    <td class="product-subtotal"><span class="amount"><?php echo $_COOKIE['fiyat'.$key]; ?>₺</span></td>
                                </tr>
                                <?php
    
    
                                $sepettoplam=$geneltoplam + $_COOKIE['fiyat'.$key];
                                $geneltoplam=$sepettoplam;
    
                                setcookie(toplam, $geneltoplam);
    
                                ?>
    
    
    
                            <?php } ?>
    
    
    
    
    
                        </tbody>
                    </table>
                </div>
    
                <div class="row">
                    <div class="col-md-5 ml-auto">
                        <div class="cart-page-total">
                            <h2>Toplam fiyat</h2>
                            <ul>
                                <li>Genel toplam <span><?php echo $geneltoplam ?>₺</span></li>
                            </ul>
                            <a href="odeme/index">Alışverişi tamamla</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    </div>
    </div>
    <!--Shopping Cart Area End-->
    <?php require_once 'footer.php';  ?>