Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset ($_POST['submit'])){
- foreach ($_POST['quantity'] as $key => $val) {
- if($val == 0){
- unset ($_SESSION['cart'][$key]);
- }
- else{
- $_SESSION['cart'][$key]['quantity'] = $val;
- }
- }
- }
- ?>
- <h1> Vizualizati cosul de cumparaturi </h1>
- <a href = "index.php?page=pizza"> Inapoi la meniu </a>
- <form method = "post" action = "index.php?page=cart">
- <table>
- <tr id = "TableHead2">
- <th> Denumire </th>
- <th> Cantitate </th>
- <th> Pret/buc </th>
- <th> Pret total </th>
- </tr>
- <?php
- $sql = "SELECT * FROM produse WHERE ID_Produs IN (";
- foreach($_SESSION['cart'] as $id => $value) {
- $sql .= $id . ",";
- }
- $sql = substr($sql, 0, -1).");";
- $query = mysql_query($sql);
- $totalprice = 0;
- if ($query)
- while($row = mysql_fetch_array ($query)){
- $subtotal = $_SESSION['cart'][$row['ID_Produs']]['quantity'] * $row['Pret'];
- $totalprice += $subtotal;
- ?>
- <tr>
- <td> <?php echo $row['Nume'] ?> </td>
- <td> <input type = "text" name = "quantity[<?php echo $row['ID_Produs'] ?>]" size = "5" value = "<?php echo $_SESSION['cart'][$row['ID_Produs']]['quantity'] ?>" /> </td>
- <td> <?php echo $row['Pret'] ?> lei</td>
- <td> <?php echo $_SESSION['cart'][$row['ID_Produs']]['quantity'] * $row['Pret'] ?> lei </td>
- </tr>
- <?php
- }
- ?>
- <tr id = "TotalPrice">
- <td colspan = "4">Total: <?php echo $totalprice ?> lei</td>
- </tr>
- </table>
- <br />
- <button type = "submit" name = "submit"> Modifica </button>
- </form>
- <br />
- <p>Pentru a sterge un produs din cos, setati cantitatea la 0. </p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement