/
wall_process.php
executable file
·56 lines (56 loc) · 1.5 KB
/
wall_process.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
50
51
52
53
54
55
56
<?php
//Wall Page
session_start();
require ('new-connection.php');
if(isset($_POST['action']) && $_POST['action'] == 'wall_post')
{
post_message($_POST);
}
elseif(isset($_POST['action']) && $_POST['action'] == 'wall_comment')
{
post_comment($_POST);
}
function post_message($post)
{
if(empty($post['messages']))
{
$_SESSION['errors'][] = "Please submit a message.";
header("Location: success.php");
die();
}
elseif(!empty($post['messages']))
{
$query = "INSERT INTO messages (message, created_at, updated_at, users_id)
VALUES ('{$post['messages']}', NOW(), NOW(), '{$_SESSION['user_id']}')";
run_mysql_query($query);
$query = "SELECT * FROM users
LEFT JOIN messages
ON users.id = messages.users_id
ORDER BY messages.created_at ASC";
$_SESSION['records'] = fetch_all($query);
header("Location: success.php");
exit();
}
}
function post_comment($post)
{
if(empty($post['comments']))
{
$_SESSION['errors'][] = "Please submit a comment.";
header("Location: success.php");
exit();
}
elseif(!empty($post['comments']))
{
$query = "INSERT INTO comments (comment, created_at, updated_at, users_id, messages_id)
VALUES ('{$post['comments']}', NOW(), NOW(), '{$post['user_id']}', '{$post['message_id']}')";
run_mysql_query($query);
$query = "SELECT * FROM users
LEFT JOIN comments
ON users.id = comments.users_id";
$_SESSION['comments'] = fetch_all($query);
header("Location: success.php");
die();
}
}
?>