Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3.     if (isset ($_POST['submit'])){
  4.         foreach ($_POST['quantity'] as $key => $val) {
  5.             if($val == 0){
  6.                 unset ($_SESSION['cart'][$key]);
  7.             }
  8.             else{
  9.                 $_SESSION['cart'][$key]['quantity'] = $val;
  10.             }
  11.         }
  12.     }
  13.  
  14. ?>
  15.  
  16. <h1> Vizualizati cosul de cumparaturi </h1>
  17. <a href = "index.php?page=pizza"> Inapoi la meniu </a>
  18. <form method = "post" action = "index.php?page=cart">
  19.      
  20.     <table>
  21.          
  22.         <tr id = "TableHead2">
  23.             <th> Denumire </th>
  24.             <th> Cantitate </th>
  25.             <th> Pret/buc </th>
  26.             <th> Pret total </th>
  27.         </tr>
  28.          
  29.         <?php
  30.          
  31.             $sql = "SELECT * FROM produse WHERE ID_Produs IN (";
  32.                      
  33.                     foreach($_SESSION['cart'] as $id => $value) {
  34.                         $sql .= $id . ",";
  35.                     }
  36.                      
  37.                     $sql = substr($sql, 0, -1).");";
  38.                     $query = mysql_query($sql);
  39.                     $totalprice = 0;
  40.                     if ($query)
  41.                         while($row = mysql_fetch_array ($query)){
  42.                             $subtotal = $_SESSION['cart'][$row['ID_Produs']]['quantity'] * $row['Pret'];
  43.                             $totalprice += $subtotal;
  44.                         ?>
  45.                             <tr>
  46.                                 <td> <?php echo $row['Nume'] ?> </td>
  47.                                 <td> <input type = "text" name = "quantity[<?php echo $row['ID_Produs'] ?>]" size = "5" value = "<?php echo $_SESSION['cart'][$row['ID_Produs']]['quantity'] ?>" /> </td>
  48.                                 <td> <?php echo $row['Pret'] ?> lei</td>
  49.                                 <td> <?php echo $_SESSION['cart'][$row['ID_Produs']]['quantity'] * $row['Pret'] ?> lei </td>
  50.                             </tr>
  51.                         <?php
  52.                              
  53.                         }
  54.         ?>
  55.                     <tr id = "TotalPrice">
  56.                         <td colspan = "4">Total: <?php echo $totalprice ?> lei</td>
  57.                     </tr>
  58.          
  59.     </table>
  60.     <br />
  61.     <button type = "submit" name = "submit"> Modifica </button>
  62. </form>
  63. <br />
  64. <p>Pentru a sterge un produs din cos, setati cantitatea la 0. </p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement