-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_item.php
More file actions
185 lines (177 loc) · 6.02 KB
/
edit_item.php
File metadata and controls
185 lines (177 loc) · 6.02 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html lang="en">
<?php
include "head.php";
?>
<?php
session_start(); //starts the session
if($_SESSION['user']){ // checks if the user is logged in
}
else{
header("location: index.php"); // redirects if user is not logged in
}
$user = $_SESSION['user']; //assigns user value
?>
<body>
<div class="container">
<header>
<div class="logo" >Indus Shop Database Management Home Page</div>
<nav class="float-right">
<div class="pure-menu pure-menu-open pure-menu-horizontal">
<ul>
<li><a href="index.php">Go back</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div>
</nav>
</header>
<h2 align="center">Edit Item Details</h2>
<table class="pure-table pure-table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Description</th>
<th>Condition</th>
<th>Customer_ID</th>
<th>Client_ID</th>
<th>Collector_ID</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($_GET['id']))
{
$id = $_GET['id'];
$_SESSION['id'] = $id;
$id_exists = true;
include "connect.inc.php";//connect to database
$query = mysql_query("Select * from item Where item_id='$id'"); // SQL Query
$count = mysql_num_rows($query);
if($count > 0)
{
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo '<td align="center">'. $row['item_id'] . "</td>";
echo '<td align="center">'. $row['name'] . "</td>";
echo '<td align="center">'. $row['description'] . "</td>";
echo '<td align="center">'. $row['condition'] . "</td>";
if ($row['customer_id'] == NULL)
{
echo '<td align="center">'. 'Not yet sold' . "</td>";
}
else
{
echo '<td align="center">'. $row['customer_id'] . "</td>";
}
echo '<td align="center">'. $row['client_id'] . "</td>";
echo '<td align="center">'. $row['collector_id'] . "</td>";
echo '<td align="center"> <a href="deleteitem.php?id='. $row['item_id'] .'"> delete </a></td>';
echo "</tr>";
$name=$row['name'];
$description=$row['description'];
$condition=$row['condition'];
$customer_id=$row['customer_id'];
$client_id=$row['client_id'];
$collector_id=$row['collector_id'];
}
}
else
{
$id_exists = false;
}
}
?>
</tbody>
</table>
<?php
$customer_query=mysql_query("SELECT customer_id FROM customer") or die ("Error Occurred");
$client_query=mysql_query("SELECT client_id FROM client") or die ("Error Occurred");
$collector_query=mysql_query("SELECT collector_id FROM collector") or die ("Error Occurred");
?>
<br/>
<br/>
<form class="pure-form pure-form-aligned" action="edititem.php" method="POST">
<fieldset>
<div class="pure-control-group">
<label for="name">Item Name</label>
<?php
echo '<input id="name" type="text" value="'.$name.'" name="name">';
?>
</div>
<?php
echo '<input type="hidden" value="'.$id.'" name="item_id">';
?>
<div class="pure-control-group">
<label for="description">Item Description</label>
<?php
echo '<input id="description" type="text" value="'.$description.'" name="description">';
?>
</div>
<div class="pure-control-group">
<label for="condition">Condition</label>
<?php
echo '<input id="condition" type="text" value="'.$condition.'" name="condition">';
?>
</div>
<div class="pure-control-group">
<label for="customer_id">Customer ID</label>
<select name = "customer_id">
<?php
while ($row=mysql_fetch_array($customer_query)) {
$cdTitle=$row["customer_id"];
if($customer_id==$cdTitle){
echo "<option value='$cdTitle' selected> $cdTitle </option>";
}
else{
echo "<option value='$cdTitle'> $cdTitle </option>";
}
}
?>
<option value=''> </option>
</select>
</div>
<div class="pure-control-group">
<label for="client">Client ID</label>
<select name = "client_id">
<?php
while ($row=mysql_fetch_array($client_query)) {
$cdTitle=$row["client_id"];
if($client_id==$cdTitle){
echo "<option value='$cdTitle' selected> $cdTitle </option>";
}
else{
echo "<option value='$cdTitle'> $cdTitle </option>";
}
}
?>
</select>
</div>
<div class="pure-control-group">
<label for="collector">Collector ID</label>
<select name = "collector_id">
<?php
while ($row=mysql_fetch_array($collector_query)) {
$cdTitle=$row["collector_id"];
if($collector_id==$cdTitle){
echo "<option value='$cdTitle' selected> $cdTitle </option>";
}
else{
echo "<option value='$cdTitle'> $cdTitle </option>";
}
}
?>
</select>
</div>
<div class="pure-controls">
<button type="submit" class="pure-button pure-button-primary">Update</button>
</div>
</fieldset>
</form>
<?php
include "footer.php";
?>
</div>
</body>
</html>