/
process_text.php
50 lines (47 loc) · 1.51 KB
/
process_text.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
<?php
session_start();
require_once("new_connection.php");
if(isset($_POST['action']) && $_POST['action'] == 'messaging')
{
insert_message($_POST);
}
if(isset($_POST['action']) && $_POST['action'] == 'comments')
{
insert_comment($_POST);
}
function insert_message($post) // This is just a parameter named $post, not the actual variable $_POST
{
// Making sure that the message is not blank, not gonna allow people to post blank messages. That would be annoying.
if(trim($post['message']) == "")
{
$_SESSION['blank'] = "Your message cannot be blank!";
header('Location: wall.php');
exit();
}
if(!trim($post['message']) == "")
{
$query = "INSERT INTO messages (user_id, message, created_at, updated_at) VALUES ('{$_SESSION['user_id']}', '{$post['message']}', NOW(), NOW())";
run_mysql_query($query);
header('Location: wall.php');
exit();
}
}
function insert_comment($post) // This is just a parameter called $post, it takes $_POST as its input
{
// Making sure that comment is not empty, don't want any empty comments clogging up my database
if(empty($post['comment']))
{
$_SESSION['blank'] = "Your comment cannot be blank!";
header('Location: wall.php');
exit();
}
if(!empty($post['comment']))
{
$query = "INSERT INTO comments (message_id, user_id, comment, created_at, updated_at)
VALUES ('{$post['message_id']}', '{$_SESSION['user_id']}', '{$post['comment']}', NOW(), NOW())";
run_mysql_query($query);
header('Location: wall.php');
exit();
}
}
?>