I am creating a very simple forum and was wondering if someone could look at my functions and make any suggestions.
Primarily about the function "bbAddNewTopic" (towards the bottom).
Does it make sense what I have done? I am using calls to OTHER functions within it without checking to see if each one returns true before moving on. Is that a bad idea? Should I use a conditional for each call to a function within it?
Please advise.
Thanks.
<?php
// function to create new topic
function bbCreateTopic($forumID, $authorID, $topicTitle, $display='yes') {
// CREATE TOPIC
$query = "INSERT INTO bb_topics
VALUES (NULL,
'".cleanstring($topicTitle)."',
$authorID,
$authorID,
'".date('Y-m-d h:i:s')."',
'".date('Y-m-d h:i:s')."',
".$forumID.",
0,
1,
'',
0,
0,
'".$display."')";
if(!$result = @mysql_query($query)) return false;
else return mysql_insert_id();
}
// function to update a topic
function bbUpdateTopic($topicID, $postID) {
// UPDATE TOPIC
$query = "UPDATE bb_topics
SET topic_last_post_id = ".$postID.",
topic_posts=(topic_posts + 1)
WHERE topic_id = ".$topicID."
LIMIT 1";
if(!$result = @mysql_query($query)) return false;
else return true;
}
// function to insert new post
function bbnewPost($forumID, $topicID, $posterID, $text, $display='yes', $subject='') {
if(isset($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
else $ip = '';
// INSERT POST
$query = "INSERT INTO bb_posts
VALUES (NULL,
$forumID,
$topicID,
$posterID,
'".cleanstring($text)."',
'".cleanstring($subject)."',
'".date('Y-m-d h:i:s')."',
'$ip',
'$display')";
if(!$result = @mysql_query($query)) return false;
else return mysql_insert_id();
}
// function to update total forum posts
function bbUpdateForumTotals($forumID, $addTopic=0) {
// UPDATE FORUM:
$query = "UPDATE bb_forums
SET topics=(topics + ".$addTopic."),
posts=(posts + 1)
WHERE forum_id = ".$forumID."
LIMIT 1";
if(!$result = @mysql_query($query)) return false;
else return true;
}
// function to update total posts / topic and last poster info.
function bbUpdateTopicTotals($topicId, $posterID, $lastpostID) {
// UPDATE TOPIC:
$query = "UPDATE bb_topics
SET topic_posts=(topic_posts + 1),
topic_last_poster_id = ".$posterID.",
topic_last_post_time = '".date('Y-m-d h:i:s')."',
topic_last_post_id = ".$lastpostID."
WHERE topic_id = ".$topicId."
LIMIT 1";
if(!$result = @mysql_query($query)) return false;
else return true;
}
// function to add a new topic
function bbAddNewTopic($forumID,$authorID,$title,$text,$display='yes') {
// create new topic
$newTopic = bbCreateTopic($forumID,$authorID,$title,$display);
// insert new post
$newPost = bbnewPost($forumID,$newTopic,$authorID,$text,$display);
// update topic
$updateTopic = bbUpdateTopic($newTopic, $newPost);
// update forum with new topic
$updateForums = bbUpdateForumTotals($forum,1);
if($newTopic == true && $newPost == true && $updateTopic == true && $updateForums == true) return true;
else return false;
}
?>