summaryrefslogtreecommitdiff
path: root/add_diary.php
blob: 9a470e8ccd287e4534d66d5bacb2a867237a8023 (plain)
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
<?php

# include the main site config where various global variables
# and libraries are included
require("config.php");

# the user must be logged in to access this script. if they are
# not then this function will send them back to the index page
loginRequired();

$newDiaryName = trim($_POST['newDiaryName']);
if ( empty($newDiaryName) ) {
	$_SESSION['systemMsg'] = "<span class='msgError'>You must give the diary a name before you can save it.</span>";
	header("Location: {$config->_previousUri}");
	exit;
}

$sql = sprintf ("
	INSERT INTO userDiaries (user, description)
	VALUES('%s','%s')
	",
	$_SESSION['user']['id'],
	$db->escapeString($newDiaryName)
);
$db->Modify($sql);

if ( $db->_affectedRows == 1 ) {
	$_SESSION['systemMsg'] = "<span class='msgOkay'>The diary was created successfully.</span>";
} else {
	$_SESSION['systemMsg'] = "<span class='msgError'>There was an error while creating the diary.</span>";
}

header("Location: {$config->_previousUri}");
exit;

?>