Home arrow PHP arrow Page 4 - Handling Entries for a Blogger Built with PHP

Creating the displayUpdateForm() method - PHP

Are you searching for an accessible guide on how to create a blog application with PHP 5? Then this set of articles might be what you’ve been looking for! Welcome to the second part of the series “Building a Blogger with PHP.” In three parts, this series demonstrates in a few easy steps how to build a classic blog application in PHP 5 by following an object-oriented approach.

TABLE OF CONTENTS:
  1. Handling Entries for a Blogger Built with PHP
  2. Defining the displayBlogs() method
  3. Defining the displayInsertForm() method
  4. Creating the displayUpdateForm() method
  5. Defining the displayHeader() and displayFooter() methods
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
November 28, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Following a similar approach to the one that I used for creating the insertion form that you learned about in the previous section, it's possible to define another important method that belongs to the "BlogProcessor" class. This one displays the required online form for updating a specific blog entry.

This being said, the signature for this broadband new method, denominated "displayUdpateForm()" is the following:

// display update form
private function displayUpdateForm(){
            $id=$this->blogData['id'];
            $result=$this->mysql->query("SELECT * FROM blogs
WHERE id='$id'");
            if($result->countRows()>0){
                        $row=$result->fetchRow();
$output=<<<EOD
<div class="dataform">
<h2>Update Blog</h2>
<form action="$_SERVER[PHP_SELF]" method="post" id="updateform">
<p>Title:</p><p><input type="text" name="title" value="$row
[title]" class="datafield" /></p>
<p>Author:</p><p><input type="text" name="author" value="$row
[author]" class="datafield" /></p>
<p>Update your content below</p><p><textarea name="content">$row
[content]</textarea></p>
<p><input type="submit" name="updateblog" value="Update
Blog" /></p>
<input type="hidden" value="$id" name="id" />
</form>
</div>
EOD;
            return $output;
            }
} 

As you'll certainly appreciate, the definition of the new method is closely similar to "displayInsertForm()", which was covered in the section you just read. This new method simply displays the corresponding update web form where all its boxes has been previously populated with the data that corresponds to the entry being updated (hence the execution of the SELECT statement in the first lines of code).

With reference to the prior method in particular, the only thing worth noticing is the inclusion of a hidden box to store the respective ID of the blog entry being updated. Quite simple, isn't it?

All right, at this stage you hopefully grasped the logic that stands behind the "BlogProcessor" class, and you understand how it displays the complete list of blogs and shows the pair of web forms necessary for inserting new blogs and updating previous ones. Thus, the next step involved in the development of this extensible blog application rests on creating three additional methods. These will be responsible for displaying programmatically the different sections that compose the main web page of the blogger, that is the header, the primary area and finally the footer.

To learn how these useful methods will be created, be a bit more patient and read the following section. We're almost finished!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: