Repository navigation
Expand file tree
/
Copy pathprocess.php
More file actions
209 lines (87 loc) · 3.02 KB
/
Copy pathprocess.php
File metadata and controls
209 lines (87 loc) · 3.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
include 'db.php';
/***********************Displaying Action Box Data ********************/
/***********************Displaying Action Box Data ********************/
if(isset($_POST['id'])) {
$id = mysqli_real_escape_string($connection, $_POST['id']);
$query = "SELECT * FROM cars WHERE id = {$id}";
$query_car_info = mysqli_query($connection, $query);
if(!$query_car_info) {
die("Query Failed" . mysqli_error($connection));
}
while($row = mysqli_fetch_array($query_car_info)) {
?>
<div class="card bg-secondary p-5">
<p id="feedback" class="bg-success"></p>
<input rel=" <?php echo $row['id']; ?>" type='text' class='mr-1 form-control title-input' value="<?php echo $row['cars']; ?> ">
<div class="d-flex mt-2 buttonall">
<input type='button' class='mr-1 btn btn-success update' value='Update'>
<input type='button' class='mr-1 btn btn-danger delete' value='Delete'>
<input type='button' class=' btn btn-close btn-warning' value='Close'>
</div><!-- /.d-flex -->
</div><!-- /.card-body -->
<?php
}
}
/*********************** Updating Data ********************/
if(isset($_POST['updatethis'])) {
$id = mysqli_real_escape_string($connection, $_POST['id']);
$tittle = mysqli_real_escape_string($connection, $_POST['title']);
$id = $_POST['id'];
$title = $_POST['title'];
$query = "UPDATE cars SET cars = '$title' WHERE id = $id ";
$result_set = mysqli_query($connection, $query);
if(!$result_set) {
die("QUERY FAILED" . mysqli_error($connection));
}
}
/*********************** Deleting Data ********************/
if(isset($_POST['deletethis'])) {
$id = mysqli_real_escape_string($connection, $_POST['id']);
$id = $_POST['id'];
$query = "DELETE FROM cars WHERE id = $id ";
$result_set = mysqli_query($connection, $query);
if(!$result_set) {
die("QUERY FAILED" . mysqli_error($connection));
}
}
?>
<script>
$(document).ready(function() {
var id;
var title;
var updatethis = "update";
var deletethis = "delte";
/* Extract id and titles */
$('.title-input').on('input', function() {
id = $(this).attr('rel');
title = $(this).val();
}); // fetch valude when user will inout for updating
/* update function */
$('.update').on('click', function() {
$.post('process.php', {
id: id,
title: title,
updatethis: updatethis
}, function(data) {
$("#feedback").text("Record updated successfully");
});
}); //update
/* delete function */
$(".delete").on('click', function() {
if (confirm('Are you sure you want to delete this')) {
id = $(".title-input").attr('rel');
$.post("process.php", {
id: id,
deletethis: deletethis
}, function(data) {
$("#action-container").hide();
});
}
}); // delete
/*********** Close Button Function *************/
$(".btn-close").on('click', function(){
$("#action-container").hide();
});
}); // document ready
</script>