-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.php
49 lines (47 loc) · 1.81 KB
/
message.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
49
<?php
if(!isset($_SESSION)){
session_start();
}
include('config.php');
include('variableAndFunctions.php');
if (isset($_POST['action']) and $_POST['action'] == 'sendmessage') {
$name = htmlspecialchars(escape($_POST['name']));
$message = htmlspecialchars(escape($_POST['message']));
$verification = ($_POST['verification']);
$timedate = escape(date("Y-m-d H:i:s"));
if (empty($name)) {
$_SESSION['msg'] = "Input fields cannot be empty!";
redirect('/index.php');
} elseif (empty($message)) {
$_SESSION['msg'] = "Input fields cannot be empty!";
redirect('/index.php');
} elseif (empty($verification)) {
$_SESSION['msg'] = "Input fields cannot be empty!";
redirect('/index.php');
} else {
if ($previousSumRandNum == $verification) {
$name=mysqli_real_escape_string($dbconnect, htmlspecialchars($name));
$message=mysqli_real_escape_string($dbconnect, htmlspecialchars($message));
$messageQuery = "INSERT INTO `$dbname`.`$tablename` (`id`, `name`, `message`, `date`) VALUES (NULL, '$name', '$message', '$timedate');";
$sendMessage = mysqli_query($dbconnect, $messageQuery);
if ($sendMessage) {
$_SESSION['msg'] = "Message Added!";
unset($_SESSION['sumRandNum']);
redirect('/index.php');
} else {
$_SESSION['msg'] = "Failed adding your message!";
unset($_SESSION['sumRandNum']);
redirect('/index.php');
exit;
}
} else {
$_SESSION['msg'] = "Verification failed!";
unset($_SESSION['sumRandNum']);
redirect('/index.php');
exit;
}
}
} else {
unset($_SESSION['sumRandNum']);
redirect('/index.php');
}