-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
131 lines (96 loc) · 3.09 KB
/
functions.php
File metadata and controls
131 lines (96 loc) · 3.09 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
<?php
// External files
require_once('config.php');
function createPostetNote($arr) {
extract($arr);
global $mysqli;
if(!isset($short_name, $long_desc, $creator_name)) {
return "An error occurred. Please make sure you have submitted acceptable values. \n Function Error " . __LINE__;
}
if(!$short_name) {
return "Please enter a short name";
} elseif(!$long_desc) {
return "Please enter a long description";
} elseif(!$creator_name) {
return "Please enter your name";
}
// Check connection
if ($mysqli->connect_error) {
return "An error occurred. Your submission was not saved. \n " . $mysqli->connect_error;
}
// prepare and bind
$stmt = $mysqli->prepare("INSERT INTO notes (short_name, long_desc, creator_name) VALUES (?, ?, ?)");
if($stmt == false)
return "An error occurred. Your submission was not saved. \n Query Error " . __LINE__;
$stmt->bind_param("sss", $short_name, $long_desc, $creator_name);
$stmt->execute();
$stmt->close();
return;
}
function getPostetNotes($arr) {
extract($arr);
global $mysqli;
// Check connection
if ($mysqli->connect_error) {
return "An error occurred while connecting to the database. \n " . $mysqli->connect_error;
}
// Gather info from db
$res = $mysqli->query('SELECT note_id, short_name, long_desc, creator_name FROM notes');
if($res == false) {
return "An error occurred. \n Query Error " . __LINE__;
}
return $res;
}
function deletePostetNote($arr) {
extract($arr);
global $mysqli;
if(!isset($note_id) || !ctype_digit($note_id)) {
return "An error occurred. Please make sure you have submitted acceptable values. \n Function Error " . __LINE__;
}
// Check connection
if ($mysqli->connect_error) {
return "An error occurred while connecting to the database. \n " . $mysqli->connect_error;
}
// prepare and bind
$stmt = $mysqli->prepare("DELETE FROM notes WHERE note_id = ?");
if($stmt == false)
return "An error occurred. Your submission was not saved. \n Query Error " . __LINE__;
$stmt->bind_param("i", $note_id);
$stmt->execute();
$stmt->close();
return;
}
function updatePostetNote($arr) {
extract($arr);
global $mysqli;
if(!isset($note_id, $short_name, $long_desc, $creator_name)) {
return "An error occurred. Please make sure you have submitted acceptable values. \n Function Error " . __LINE__;
}
if(!$short_name) {
return "Please enter a short name";
} elseif(!$long_desc) {
return "Please enter a long description";
} elseif(!$creator_name) {
return "Please enter your name";
} elseif(!$note_id) {
return "Unable to find that note";
}
// Check connection
if ($mysqli->connect_error) {
return "An error occurred. Your submission was not saved. \n " . $mysqli->connect_error;
}
// prepare and bind
$stmt = $mysqli->prepare("
UPDATE notes
SET short_name = ?,
long_desc = ?,
creator_name = ?
WHERE note_id = ?
");
if($stmt == false)
return "An error occurred. Your submission was not saved. \n Query Error " . __LINE__;
$stmt->bind_param("sssi", $short_name, $long_desc, $creator_name, $note_id);
$stmt->execute();
$stmt->close();
return;
}