13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

764 Chapter 31 Building <strong>Web</strong> Forums<br />

Listing 31.8<br />

Continued<br />

$parent = $_POST['parent'];<br />

}<br />

if(!$area) {<br />

$area = 1;<br />

}<br />

if(!$error) {<br />

if(!$parent) {<br />

$parent = 0;<br />

if(!$title) {<br />

$title = 'New Post';<br />

}<br />

} else {<br />

// get post name<br />

$title = get_post_title($parent);<br />

// append Re:<br />

if(strstr($title, 'Re: ') == false) {<br />

$title = 'Re: '.$title;<br />

}<br />

//make sure title will still fit in db<br />

$title = substr($title, 0, 20);<br />

//prepend a quoting pattern to the post you are replying to<br />

$message = add_quoting(get_post_message($parent));<br />

}<br />

}<br />

do_html_header($title);<br />

display_new_post_form($parent, $area, $title, $message, $poster);<br />

if($error) {<br />

echo "Your message was not stored.<br />

Make sure you have filled in all fields <strong>and</strong><br />

try again.";<br />

}<br />

do_html_footer();<br />

?><br />

After some initial setup, the new_post.php script checks whether the parent is 0 (zero)<br />

or otherwise. If it is 0, this topic is new, <strong>and</strong> little further work is needed.<br />

If this message is a reply ($parent is the postid of an existing article), the script goes<br />

ahead <strong>and</strong> sets up the title <strong>and</strong> text of the original message, as follows:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!