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.

Adding New Articles<br />

769<br />

Listing 31.13<br />

Continued<br />

<strong>and</strong> title = '".$post['title']."'<br />

<strong>and</strong> body.postid is NULL";<br />

$result = $conn->query($query);<br />

if (!$result) {<br />

return false;<br />

}<br />

if($result->num_rows>0) {<br />

$this_row = $result->fetch_array();<br />

$id = $this_row[0];<br />

}<br />

if($id) {<br />

$query = "insert into body values<br />

($id, '".$post['message']."')";<br />

$result = $conn->query($query);<br />

if (!$result) {<br />

return false;<br />

}<br />

}<br />

return $id;<br />

}<br />

This function is long but not overly complex. It is only long because inserting a posting<br />

means inserting entries in the header <strong>and</strong> body tables <strong>and</strong> updating the parent article’s<br />

row in the header table to show that it now has children.<br />

That is the end of the code for the web forum application.<br />

Adding Extensions<br />

There are many extensions you could add to this project:<br />

n<br />

n<br />

n<br />

n<br />

You could add navigation to the view options so that from a post, you could navigate<br />

to the next message, the previous message, the next-in-thread message, or the<br />

previous-in-thread message.<br />

You could add an administration interface for setting up new forums <strong>and</strong> deleting<br />

old posts.<br />

You could add user authentication so that only registered users could post.<br />

You could add some kind of moderation or censorship mechanism.<br />

Look at existing systems for ideas.

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

Saved successfully!

Ooh no, something went wrong!