-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.php
34 lines (28 loc) · 904 Bytes
/
send.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
<?php
// Set up all variables
$response = array();
$response['request'] = 'failed';
$response['error'] = 'unknown';
// Connenct to database
include 'mysqlcredentials.php';
// Check connection
if ($pdo === false) {
$response['error'] = 'Could not connect to database.';
goto end;
} else {
$name = $_POST['name'];
$klasse = $_POST['klasse'];
$wunsch = $_POST['wunsch'];
// prepare statement
$statement = $pdo->prepare("INSERT INTO nachrichten (name, klasse, wunsch) VALUES (?, ?, ?)");
// execute statement and put response into array
$statement->execute(array($name, $klasse, $wunsch));
// response
if ($statement->rowCount() == 1) {
$response['request'] = 'success';
unset($response['error']);
}
}
end:
// Encode response array into json
echo json_encode($response, JSON_PRETTY_PRINT);