-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_products.php
157 lines (142 loc) · 4.12 KB
/
action_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
session_start();
function checkSession() {
if(empty($_SESSION["admin"])) return false;
return true;
}
function makeInsertForm() {
echo "<h3 align=center>Insert a swimwear </h3>";
echo "<form method=post action=insert_product.php>";
echo "<table align=center border=1>";
echo "<tr>";
echo "<td>Name:</td>";
echo "<td><input type=text name=name></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Size:</td>";
echo "<td><input type=text name=size></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Color:</td>";
echo "<td><input type=text name=color></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Price:</td>";
echo "<td><input type=text name=price></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Items:</td>";
echo "<td><input type=text name=items></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Click here</td>";
echo "<td align=right><input type=submit value=ok></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
function makeDisplayForm() {
echo "<h3> Swimwears </h3>";
include("mysql.php");
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db);
$sql="select code from users where username='".$_SESSION["admin"]."'";
$res=mysql_query($sql);
$row=mysql_fetch_array($res,MYSQL_BOTH);
$usercode=$row["code"];
$sql="select * from swimwears where usercode=$usercode";
$res=mysql_query($sql);
echo "<table align=center border=1>";
echo "<tr>";
echo "<td>Name</td><td>Size</td><td>Color</td><td>Price</td><td>Items</td>";
echo "</tr>";
while($row=mysql_fetch_array($res,MYSQL_BOTH)){
echo "<tr>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["size"]."</td>";
echo "<td>".$row["color"]."</td>";
echo "<td>".$row["price"]."</td>";
echo "<td>".$row["items"]."</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($link);
}
function makeDeleteForm() {
echo "<h3> Delete Items </h3>";
include("mysql.php");
$link=mysql_connect($host,$user,$pass);
mysql_select_db($database);
$sql="select code from users where username='".$_SESSION["admin"]."'";
$res=mysql_query($sql);
$row=mysql_fetch_array($res,MYSQL_BOTH);
$usercode=$row["code"];
$sql="select name from swimwears where usercode=$usercode";
$res=mysql_query($sql);
echo "<form method=post action=delete_product.php>";
echo "Name of the product:";
echo "<select name=name>";
while($row=mysql_fetch_array($res,MYSQL_BOTH)) {
echo "<option>".$row["name"]."</option>"; }
echo "</select>";
echo "<input type=submit value=ok>";
echo "</form>";
mysql_close($link);
}
function makeBuyForm() {
echo "<h3> Buy form </h3>";
include("mysql.php");
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db);
$sql="select code from users where username='".$_SESSION["admin"]."'";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
$thiscode=$row["code"];
//select products of the other users
$sql="select * from swimwears where usercode<>$thiscode";
$res=mysql_query($sql);
echo "<table align=center border=1>";
echo "<tr>";
echo "<td>Product name </td><td>Price</td><td>Available items</td><td>Quantity</td>";
echo "</tr>";
while($row=mysql_fetch_array($res,MYSQL_BOTH)) {
echo "<tr>";
echo "<form method=post action=buy.php>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["price"]."</td>";
echo "<td>".$row["items"]."</td>";
echo "<td><input type=text name=items></td>";
echo "<td><input type=submit value=ok></td>";
echo "<input type=hidden name=productname value=".$row["name"].">";
echo "<input type=hidden name=productcode value=".$row["code"].">";
echo "<input type=hidden name=usercode value=".$thiscode.">";
echo "</form>";
echo "</tr>";
}
echo "</table>";
mysql_close($link);
}
function makeBack() {
echo "<a href=login.php>Back</a>"; }
if(!checkSession()) {
makeBack();
die("<h4>Incorrect entry</h4>");
}
if(empty($_POST["productlist"])) {
makeBack();
die("<h4>Incorrect entry </h4>");
}
echo "<p align=right>";
echo "<a href=logout.php>logout</a>";
echo "</p>";
$option=$_POST["productlist"];
if($option=="insert")
makeInsertForm();
else if($option=="display")
makeDisplayForm();
else if($option=="delete")
makeDeleteForm();
else
makeBuyForm();
makeBack();
?>