-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataFetch.php
More file actions
72 lines (68 loc) · 2.27 KB
/
dataFetch.php
File metadata and controls
72 lines (68 loc) · 2.27 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
<?php
$insert = false;
$update = false;
$delete = false;
if (isset($_GET['delete'])) {
$sno = $_GET['delete'];
$delete = true;
$sql = "DELETE FROM `enotes` WHERE `sno` = $sno";
$result = mysqli_query($conn, $sql);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['snoEdit'])) {
// Update the record
$sno = $_POST["snoEdit"];
$title = $_POST["titleEdit"];
$description = $_POST["descriptionEdit"];
// Sql query to be executed
$sql = "UPDATE `enotes` SET `title` = '$title' , `description` = '$description' WHERE `enotes`.`sno` = $sno";
$result = mysqli_query($conn, $sql);
if ($result) {
$update = true;
} else {
echo "We could not update the record successfully";
}
} else {
$title = $_POST["title"];
$description = $_POST["description"];
// Sql query to be executed
$sql = "INSERT INTO `enotes` (`title`, `description`) VALUES ('$title', '$description')";
$result = mysqli_query($conn, $sql);
if ($result) {
$insert = true;
} else {
echo "The record was not inserted successfully because of this error ---> " . mysqli_error($conn);
}
}
}
?>
<?php
if ($insert) {
echo "<div class='alert alert-success alert-dismissible fade show m-0' role='alert'>
<strong>Success!</strong> Your note has been inserted successfully
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}
?>
<?php
if ($delete) {
echo "<div class='alert alert-success alert-dismissible fade show m-0' role='alert'>
<strong>Success!</strong> Your note has been deleted successfully
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}
?>
<?php
if ($update) {
echo "<div class='alert alert-success alert-dismissible fade show m-0' role='alert'>
<strong>Success!</strong> Your note has been updated successfully
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}
?>