-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_car.php
More file actions
111 lines (70 loc) · 3.91 KB
/
view_car.php
File metadata and controls
111 lines (70 loc) · 3.91 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
<?php
session_start();
// if user is not logged in
if(!$_SESSION['loggedinUser']){
// send them to the login page
header("Location: signin.php");
}
$carID = $_GET['id'];
include('includes/connection.php');
$query = "SELECT * FROM car_directory WHERE id = $carID ";
$result = mysqli_query($conn, $query);
// if delete button was submitted
if(isset($_POST["delete"])){
echo "<div style='margin: 50px;'>
$alertMessage = <div class='alert alert-danger'>
<p>Are you sure you want to delete this car ad? No take backs!</p><br>
<form action='".htmlspecialchars($_SERVER["PHP_SELF"])."?id=$carID' method='post'>
<input type='submit' class='btn btn-danger btn-sm' name='confirm-delete' value='Yes! Delete!'>
<a type='button' class='btn btn-light btn-outline-dark btn-sm' data-dismiss='alert'>Oops, No thanks!</a>
</form>
</div>
</div>";
}
if(isset($_POST["confirm-delete"])){
// new database query and result
$query = "DELETE FROM car_directory WHERE id = '$carID'";
$result = mysqli_query($conn,$query);
if($result){
// redirect to client page with query string
header("Location: show_car.php?alert=deleted");
}else{
echo "Error updating record: " . mysqli_error($conn);
}
}
// if confirm delete button was pressed
// close the mysql connection
include('includes/header.php');
?>
<?php echo $alertMessage; ?>
<?php
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
echo "
<div class='container'>
<h3 class= 'mb-3' style='margin-top:70px;'>Car Details</h3>
<div class='row'>
<div class='col-sm-8'>
<p class='lead'>Car Production Year: <big>".$row['production_year']."</big></p>
<p class='lead'>Car Manufacturer: <big>".$row['manufacturer']."</big></p>
<p class='lead'>Car Model: <big>".$row['model']."</big></p>
<p class='lead'>Car Rent: <big>".$row['rent']."<small>$ per day</small></big></p>
<p class='lead'>Description: <big>".$row['description']."</big></p>
<form action='".htmlspecialchars($_SERVER["PHP_SELF"])."?id=".$carID."' method='post'>
<button style='margin: 135px 20px 0 0;' type='submit' class='btn btn-lg btn-danger float-left' name='delete'>Delete this ad</button>
</form>
</div>
<div class='col-sm-4'>
<div class='rounded float-right'>
<img style='width:400px; height:300px;' src='data:image;base64,".$row['picture']."'>
<p class='card-text'><a href='book_car.php?id=".$row['id']."' class='btn btn-lg btn-primary' style='margin:100px 0 0 250px;'>Book this car</a></p>
</div>
</div>
</div>
</div>" ;
}
}
?>
<?php
include('includes/footer.php');
?>