-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.php
97 lines (57 loc) · 2.16 KB
/
process.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
<?php
include 'connection.php';
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)){
echo "<input rel='".$row['id']."' type='text' class='form-control title-input' value='".$row['cars']."'>";
echo "<input type='button' class='btn btn-success update' value='Update'>";
echo "<input type='button' class='btn btn-danger delete' value='Delete'>";
}
}
if(isset($_POST['updatethis'])){
$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));
}
}
if(isset($_POST['deletethis'])){
$id = $_POST['id'];
$query = "DELETE FROM cars WHERE id = $id ";
$delete_result = mysqli_query($connection,$query);
if(!$delete_result){
die("Query failed". mysqli_error($connection));
}
}
?>
<script>
$(document).ready(function(){
var id;
var title;
var updatethis = "update";
var deletethis = "delete";
$(".title-input").on('input',function(){
id = $(this).attr('rel');
title = $(this).val();
});
$(".update").on('click',function(){
$.post("process.php",{id:id,title:title, updatethis:updatethis},function(data){
$("#feedback").text("Record updated successfuly");
});
});
$(".delete").on('click',function(){
id = $(".title-link").attr('rel');
$.post("process.php",{id:id,title:title, deletethis:deletethis},function(data){
$("#feedback").text("Record delete successfuly");
$("#action-container").hide();
});
});
});//ready
</script>