-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle_details.php
171 lines (100 loc) · 3.25 KB
/
vehicle_details.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
session_start();
if(!isset($_GET["vehicle_id"]) || !isset($_SESSION["email"]))
{
header("Location:display_vehicles.php");
}
else
{
echo "<img id = 'logo' src = 'images/cover.png' width='125px'>";
echo "<a href = 'logout.php' class = 'logout button'>Logout</a>";
$email = $_SESSION["email"];
$customer_id = $_SESSION["customer_id"];
$DBHOST = "localhost";
$DBUSER = "Vehiclemanagement";
$DBPWD = "Vehiclemanagement123";
$DBNAME = "vehiclemanagement";
$conn = new mysqli($DBHOST, $DBUSER, $DBPWD, $DBNAME);
if($conn->connect_error)
{
die("Connection failed!".$conn->connect_error);
}
$statement = "SELECT * FROM vehicle WHERE vehicle_id = ?";
$iid = $_GET["vehicle_id"];
$stmt = $conn->prepare($statement);
$stmt->bind_param("s", $iid);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc(); /* select the data of the specific item from the item table*/
$iid = $row["vehicle_id"];
$iname = $row["vehicle_type"];
$i_desc = $row["vehicle_desc"];
$vehicle_category = $row["vehicle_category"];
$day_uploaded = $row["day_uploaded"];
$vehicle_price = $row["vehicle_price"];
$iimg = "images/";
$iimg = $iimg.$row["vehicle_picture"];
$seller_id = $row['customer_id'];
$statement = "SELECT * FROM vehicle WHERE customer_id=?";
$stmt = $conn->prepare($statement);
$stmt->bind_param("s", $customer_id);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows >= 1)
{
$value = "seller";
}
else
{
$value= "customer";
}
echo "<div class = 'item'>";
echo "<div class = 'item_row'> Vehicle Id: $iid </div>";
echo "<div class = 'item_row'>Vehicle Type: $iname </div>";
echo "<img class = 'item_img' src = '$iimg' alt = 'image'>";
echo "<div class = 'item_row'>Vehicle Price: $vehicle_price </div>";
echo "<div class = 'item_row'> Vehicle Description: $i_desc</div>";
echo "<div class = 'item_row'> Vehicle Category: $vehicle_category</div>";
echo "<br>";
echo "<form action = 'buy.php' method='POST' onsubmit='bought();'>";
echo "<label class='label'>Transaction Code</label>";
echo "<input class='' type='text' name='transaction_code' placeholder='transaction code' required>";
echo "<br>";
echo "<input type = 'hidden' name='vehicle_id' value = '$iid' >";
echo "<input type = 'hidden' name = 'email' value = '$email'>";
echo "<input type = 'hidden' name='seller_id' value = $seller_id>";
echo "<input type = 'hidden' name='vehicle_price' value = $vehicle_price>";
if($value == "seller")
{
echo "<div class='item_row'>The vehicle is yours</div>";
}
elseif ($value == "customer")
{
echo "<input type = 'submit' value = 'Buy' class='submit' >";
}
echo "<script>
function bought(){
var r = confirm('Press ok to confirm ');
if (r == true)
{
header('Location:bought.php');
}
else {
header('Location:vehicle_details.php');
}
}
</script>";
echo "</form>";
echo "</div>";
$conn->close(); /* display the item details*/
}/* prevent direct access by user*/
?>
</body>
</html>