-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
62 lines (50 loc) · 1.56 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
<?php
session_start();
// connecting to database
$mysqli = new mysqli('localhost', 'root', '', 'crudapp' ) or die(mysqli_error($mysqli));
$name = '';
$id = '';
$location = '';
$update = false;
//check if save button has been clicked
if(isset($_POST['save'])){
$name = $_POST['name'];
$email = $_POST['email'];
//insert data to database
$mysqli->query("INSERT INTO `data` (name,email) VALUES ('$name','$email')") or die($mysqli->error);
$_SESSION['message'] = "Record has been saved";
$_SESSION['msg_type'] = "success";
//redirecting user
header("location: index.php");
}
//deleting a record
if(isset($_GET['delete'])){
$id = $_GET['delete'];
$mysqli->query("DELETE FROM data WHERE id=$id") or die($mysqli->error);
$_SESSION['message'] = "Record has been deleted";
$_SESSION['msg_type'] = "Danger";
//redirect user
header("location: index.php");
}
//editing a record
if(isset($_GET['edit'])){
$id = $_GET['edit'];
$update=true;
$result = $mysqli->query("SELECT * FROM data WHERE id=$id") or die($mysqli->error);
if(count($result)==1){
$row = $result->fetch_array();
$name = $row['name'];
$email = $row['email'];
}
}
//updating
if(isset($_POST['update'])){
$id=$_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$mysqli->query("UPDATE data SET name = '$name', location = '$location' WHERE id = $id") or die($mysqli->error);
$_SESSION['message']= "Record has been updated";
$_SESSION['msg_type'] = "warning";
header("location: index.php");
}
?>