· 7 years ago · Sep 05, 2018, 04:08 AM
1<?php
2
3include '../../links/db.php';
4
5if(isset($_POST['add'])){
6 if(!empty($_POST['it'])){
7 if(!empty($_POST['q'])){
8 if(!empty($_POST['p'])){
9 $it=mysqli_real_escape_string($con, $_POST['it']);
10 $q=mysqli_real_escape_string($con, $_POST['q']);
11 $p=mysqli_real_escape_string($con, $_POST['p']);
12
13 $create_cart=mysqli_query($con, "CREATE TABLE IF NOT EXISTS cart(sales_person VARCHAR(20), item VARCHAR(40), quantity INT, price INT) ");
14 if($create_cart){
15 $price = $q * $p;
16 $add_to_cart=mysqli_query($con, "INSERT INTO cart (sales_person,item,quantity,price) VALUES ('chisom', '$it', '$q', '$price') ");
17 if($add_to_cart){
18 $get_from_cart=mysqli_query($con, "SELECT * FROM cart WHERE sales_person='chisom' ");
19 echo "<table class='table table-bordered table-striped'>";
20 echo "<th>items</th>";
21 echo "<th>quantity</th>";
22 echo "<th>price</th>";
23 while($row=mysqli_fetch_assoc($get_from_cart)){
24 echo "<tr>";
25 echo "<td>".$item=$row['item']."</td>";
26 echo "<td>".$row['quantity']."</td>";
27 echo "<td>N".$row['price']."</td>";
28 echo "</tr>";
29 }
30 $result=mysqli_query($con, "SELECT SUM(price) AS price_sum FROM cart");
31 $row=mysqli_fetch_assoc($result);
32 echo "<tr>";
33 echo "<th>TOTAL</th>";
34 echo "<td></td>";
35 echo "<td>N".$sum=$row['price_sum']."</td>" ;
36 echo "</tr>";
37 echo "</table>";
38
39 echo "<a href='dashboard.php?sales_person=chisom' class='btn btn-success btn-block'>SELL</a>";
40 }
41 }
42 }
43 }
44 }
45}