HomePHP Page 4 - Defining the Core Structure of a PHP Blogger
Defining the updateBlog() method - PHP
In the first part of this three-part series, we'll examine the basic outlines of creating a blog application with PHP 5. If you're currently working with PHP 4, this program can be adapted to that version of the language.
As I said in the previous section, the next step involved in creating the blog application relies on defining yet another handy method, aimed at updating an existing entry in the corresponding database table. This brand new method not surprisingly has been called "updateBlog()," and its definition is as follows:
// update blog private function updateBlog(){ $id=$this->blogData['id']; $title=$this->blogData['title']; $author=$this->blogData['author']; $content=$this->blogData['content']; $this->mysql->query("UPDATE blogs SET title='$title',author='$author',content='$content',date=TIMESTAMP(10) WHERE id='$id'"); header('Location:'.$_SERVER['PHP_SELF']); }
As shown above, the signature for the "updateBlog()" method looks nearly identical to the previous "insertBlog()" method. In this case, the only difference rests on the type of database operation that it performs, since it updates an existing blog entry instead of adding a new one.
After a particular blog has been updated, the method reloads the main page where the complete set of blogs is conveniently displayed. Quite possibly, if you used to work on a frequent basis with DML operations, you'll find the prior method pretty simple to understand. What do you think?
Well, at this point I provided you with a fairly decent explanation of how the previous "insertBlog()" and "updateBlog()" methods do their business. Therefore, it's time to examine the last method that I plan to include in the "BlogProcessor" class; in this case, I'm talking about the one called "deleteBlog()" and obviously it is responsible for removing a specified entry from the "blogs" database table.
Curious about how this new method will be coded? Go ahead and read the following section.