-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprocess.php
58 lines (54 loc) · 1.66 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
<?php
/*
Author : Suresh Pokharel
Email : [email protected]
GitHub : github.com/suresh021
URL : psuresh.com.np
*/
?>
<?php
/*Database Connection*/
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'dm';
Global $dbconfig;
$dbconfig = mysqli_connect($host,$username,$password,$database) or die("An Error occured while connecting to the database");
?>
<?php
if (isset($_GET['insert_description'])) {
$desc=$_GET['insert_description'];
if(mysqli_query($dbconfig,"INSERT INTO todo(description) values('$desc')")){
$response_array['status']="success";
}else {
$response_array['status']="error";
}
header('Content-type: application/json');//preparing correct format for json_encode
echo json_encode($response_array);//sending response to ajax
}
?>
<?php
if (isset($_GET['delete_id'])) {
$delete_id=$_GET['delete_id'];
if(mysqli_query($dbconfig,"DELETE FROM todo WHERE id=$delete_id")){
$response_array['delete_status']="success";
}else {
$response_array['delete_status']="error";
}
header('Content-type: application/json');//sending response to ajax
echo json_encode($response_array);
}
?>
<?php
if (isset($_GET['edit_id'])){
$edit_id= $_GET['edit_id'];
$new_desc= $_GET['new_desc'];
if(mysqli_query($dbconfig,"UPDATE todo SET description='$new_desc' WHERE id=$edit_id")){
$response_array['edit_status']="success";
}else {
$response_array['edit_status']="error";
}
header('Content-type: application/json');//sending response to ajax
echo json_encode($response_array);
}
?>