Repository navigation
Expand file tree
/
Copy pathsession.php
More file actions
65 lines (54 loc) · 1.33 KB
/
Copy pathsession.php
File metadata and controls
65 lines (54 loc) · 1.33 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
<html>
<head>
<base target="bottom">
</head>
<body>
<?php
session_start();
if(!empty($_REQUEST['form_products']))
{
// Assign SESSION variables to values
if(!isset($_SESSION['products']))
{
$_SESSION['products'][0] = $_REQUEST['form_products'];
$_SESSION['quantity'][0] = $_REQUEST['quantity'];
$_SESSION['id'][0] = $_REQUEST['prodId'];
$_SESSION['quant'][0] = $_REQUEST['unitQuant'];
$_SESSION['price'][0] = $_REQUEST['form_prod_price'];
}
else
{
$newProdID = $_REQUEST['prodId'];
$match = false;
for ($i=0; $i < sizeof($_SESSION['products']); $i++)
{
if($newProdID == $_SESSION['id'][$i])
{
$_SESSION['quantity'][$i]+=$_REQUEST['quantity'];
$match = true;
break;
}
}
if(!$match)
{
$_SESSION['products'][] = $_REQUEST['form_products'];
$_SESSION['quantity'][] = $_REQUEST['quantity'];
$_SESSION['id'][] = $newProdID;
$_SESSION['quant'][] = $_REQUEST['unitQuant'];
$_SESSION['price'][] = $_REQUEST['form_prod_price'];
}
}
}
else
{
print "<h1>No products to add <br> at the moment.</h1> <br>";
}
?>
<form id = "updateCart" action = "shoppingcart.php" method = "post">
<input type = "hidden" id = "update" name = "update">
<script type = "text/javascript">
document.getElementById("updateCart").submit();
</script>
</form>
</body>
</html>