Specifications

As you can see, this is a short script. Its main task is to call the store_new_post() function.
This page has no visual content of its own. If storing succeeds, we see the index page.
Otherwise, we go back to the new_post.php page, so the user can try again.
The store_new_post() function is shown in Listing 29.13.
LISTING 29.13 store_new_post() Function from discussion_fns.phpValidates and Stores
the New Post in the Database
function store_new_post($post)
{
// validate clean and store a new post
$conn = db_connect();
// check no fields are blank
if(!filled_out($post))
return false;
$post = clean_all($post);
//check parent exists
if($post[“parent”]!=0)
{
$query = “select postid from header where postid = ‘“.$post[‘parent’].”’”;
$result = mysql_query($query);
if(mysql_numrows($result)!=1)
{
return false;
}
}
// check not a duplicate
$query = “select header.postid from header, body where
header.postid = body.postid and
header.parent = “.$post[‘parent’].” and
header.poster = ‘“.$post[‘poster’].”’ and
header.title = ‘“.$post[‘title’].”’ and
header.area = “.$post[‘area’].” and
body.message = ‘“.$post[‘message’].”’”;
$result = mysql_query($query);
if (!$result)
{
return false;
}
if(mysql_numrows($result)>0)
return mysql_result($result, 0, 0);
Building Web Forums
C
HAPTER 29
29
BUILDING WEB
FORUMS
739
35 7842 CH29 3/6/01 3:34 PM Page 739