-
Notifications
You must be signed in to change notification settings - Fork 0
/
php file
45 lines (33 loc) · 1.09 KB
/
php file
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
<?php
$name = $_POST["name"];
$message = $_POST["message"];
$priority = filter_input(INPUT_POST, "priority", FILTER_VALIDATE_INT);
$type = filter_input(INPUT_POST, "type", FILTER_VALIDATE_INT);
$terms = filter_input(INPUT_POST, "terms", FILTER_VALIDATE_BOOL);
if ( ! $terms) {
die("Terms must be accepted");
}
$host = "localhost";
$dbname = "message_db";
$username = "root";
$password = "";
$conn = mysqli_connect(hostname: $host,
username: $username,
password: $password,
database: $dbname);
if (mysqli_connect_errno()) {
die("Connection error: " . mysqli_connect_error());
}
$sql = "INSERT INTO message (name, body, priority, type)
VALUES (?, ?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
if ( ! mysqli_stmt_prepare($stmt, $sql)) {
die(mysqli_error($conn));
}
mysqli_stmt_bind_param($stmt, "ssii",
$name,
$message,
$priority,
$type);
mysqli_stmt_execute($stmt);
echo "Record saved.";