-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathproducts.php
89 lines (65 loc) · 1.81 KB
/
products.php
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
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=intval($_GET['id']);
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]['quantity']++;
}else{
$conn= mysqli_connect("localhost", "root", "", "compsys");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql_s="SELECT * FROM stock
WHERE stock_id ={$id}";
//$query_s=mysql_query($sql_s);
$res = mysqli_query($conn, $sql_s);
if(mysqli_num_rows($res)!=0) {
$row_s=mysqli_fetch_array($res);
$_SESSION['cart'][$row_s['stock_id']]=array(
"quantity" => 1,
"price" => $row_s['price']
);
} else {
$message="This product id is invalid!";
}
// Free result set
mysqli_free_result($res);
mysqli_close($conn);
}
}
?>
<h1>Product List</h1>
<?php
if(isset($message)){
echo "<h2>$message</h2>";
}
?>
<table>
<tr>
<th>Stock#</th>
<th>Description</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$conn= mysqli_connect("localhost", "root", "", "compsys");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql="SELECT * FROM stock ORDER BY stock_id ASC";
$res = mysqli_query($conn, $sql);
//$result2 = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
//$query=mysql_query($sql);
while ($row=mysqli_fetch_array($res)) {
?>
<tr>
<td><?php echo $row['stock_id'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo '€' .$row['price'] ?></td>
<td><a href="chooseProducts.php?page=products&action=add&id=<?php echo $row['stock_id'] ?>">Add to cart</a></td>
</tr>
<?php
}
?>
</table>