-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.php
More file actions
89 lines (79 loc) · 2.5 KB
/
index.php
File metadata and controls
89 lines (79 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
error_reporting(0);
require_once('config.php');
//session
session_start();
//create empty array for cart
if(!isset($_SESSION['tedi'])){
$_SESSION['tedi'] = array();
}
//get current exchange rate
if(!isset($_SESSION['exr'])){
$url = "https://www.bitstamp.net/api/ticker/";
$fgc = file_get_contents($url);
$json = json_decode($fgc, TRUE);
$price = (int)$json["last"];
$_SESSION['exr'] = $price;
}
//count items in array
$cartItems = count($_SESSION['tedi']);
$cart = $_SESSION['tedi'];
//add to cart buttons
$queryProducts2 ="SELECT * FROM products WHERE in_stock > 0 ORDER BY id ASC";
$resultH2=mysqli_query($conn, $queryProducts2) or die ("database connection error check server log");
//loop through different product ids
while($outputsH2=mysqli_fetch_assoc($resultH2)){
if(isset($_POST[$outputsH2['id']])){
array_push($_SESSION['tedi'], $outputsH2['id']);
$cartItems = count($_SESSION['tedi']);
$cart = $_SESSION['tedi'];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $storeName; ?></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1><?php echo $storeName; ?></h1>
<div id="cartCont">
<div id="cartHeader">Your Cart</div>
<div id="cartSpace">
<?php
$usdOwed = 0;
for($i=0; $i<$cartItems; $i++)
{
$queryLoopCart = "SELECT * FROM products WHERE id = '$cart[$i]'";
$doLoopCart = mysqli_query($conn, $queryLoopCart);
$rowLoopCart = mysqli_fetch_assoc($doLoopCart);
$loopName = $rowLoopCart['name'];
$loopPrice = $rowLoopCart['price'];
$usdOwed += $loopPrice;
echo $loopName."<span class='cartPrice'>$".$loopPrice."</span>";
echo"<br><br>";
}
echo "</div>";
echo "<div id='cartCost'>$".$usdOwed."</div>";
?>
<form action="cart.php"><input type="submit" value="View Cart"></form>
</div>
<?php
$queryProducts ="SELECT * FROM products WHERE in_stock > 0 ORDER BY id ASC";
$resultH=mysqli_query($conn, $queryProducts) or die ("error fetching products table");
while($outputsH=mysqli_fetch_assoc($resultH)){
echo "<div class='shopCont'>";
echo "<div class='shopImg'><img src='".$outputsH['image']."'></div>";
echo "<div class='shopDesc'>";
echo "<span class='itemName'>".$outputsH['name']."</span>";
echo "<span class='itemCost'>$".$outputsH['price']."</span>";
echo $outputsH['description']."</div>";
echo "<div class='shopAdd'><form method='post'><input type='submit' value='Add To Cart' name='".$outputsH['id']."'></form></div>";
echo "</div>";
echo "<div class='shopCont'><hr></div>";
}
?>
<br>
</body>
</html>