-
Notifications
You must be signed in to change notification settings - Fork 0
/
addprayer.php
48 lines (45 loc) · 1.18 KB
/
addprayer.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
<?php
function createCxn(){
try {
$cxn = new mysqli("localhost", "jjprogra_prayers", "JJPRO_prayers", "jjprogra_prayers");
} catch (exception $e){
echo $e->getMessage();
}
if (!$cxn) {
echo 'Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error();
return FALSE;
} else return $cxn;
}
function runUpdateQuery($cxn, $query){
if ($cxn){
$results = $cxn->query($query);
if (!$results) {
echo ("FAIL");
echo ('Invalid query: ' . $cxn->error . "\n");
echo ('<br>Whole query: ' . $query);
return FALSE;
}
$numRows = $cxn->affected_rows;
return $numRows;
}
}
$name = $_POST['name'];
$details = $_POST['details'];
$type = $_POST['type'];
if (strlen($name) < 1){
echo "There is no name given!!! Quiting";
exit();
}
$query = "INSERT INTO `Prayers` (`name`, `details`, `type`)
VALUES ('".$name."','".$details."','".$type."')";
$cxn = createCxn();
if(!$cxn){
echo "Can't create Connection! Quitting";
exit();
}
if( !runUpdateQuery($cxn, $query) ){
echo "Failed to run query! Quitting";
exit();
}
echo "<h1>Success!</h1><p>The prayer has been added to the database!</p>";
?>