HTML and CSS Reference
In-Depth Information
As I said earlier I'm keen to focus on the real-time functionality so a class exists within the
template that you've downloaded which encapsulate some of the standard data checking and
persistence functionality. This class is defined in Persistence.php (you can view the source
here ), is in no way production quality, and handles:
Basic validation
Basic data sanitization
Very simple persistence using a user $_SESSION . This means that a comment saved by
one user will not be available to another user.
This also means that we don't need to spend time setting up a database and all that goes with
it and makes post_comment.php very simple an clean. If you wanted to use this functionality in
a production environment you would need to re-write the contents of Persistence.php . Here's
the code for post_comment.php .
require ( 'Persistence.php' );
$db = new Persistence ();
if ( $db -& gt ; add_comment ( $_POST ) ) {
header ( 'Location: index.php' );
else {
header ( 'Location: index.php?error=Your comment was not posted due to
errors in your form submission' );
The above code does the following:
Includes the Persistence.php class which handles saving and fetching comments.
Creates a new instances of the Persistence object and assigns it to the variable $db .
Tries to add the comment to the $db . If the comment is successfully added it redirects
back to the blog post. If it fails the redirection also occurs but some error text is
appended to an error query parameter.
Search WWH ::

Custom Search