summaryrefslogtreecommitdiff
path: root/add_diary.php
blob: 9bd8f6d2d4d7ca6e20367915ec5a42cb5ea96db4 (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
37
38
39
40
41
42
43
44
<?php

/**
 * Copyright (c) 2007 Nathan Kinkade
 * 
 * This code is offered under an MIT (X11) license.  For more information
 * about the terms of this license see the file LICENSE included with this
 * software or visit: http://www.opensource.org/licenses/mit-license.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;

?>