Building a Weblog: Part 4/Page 2
[previous] [next]
Building a Weblog: Part 4
Creating New Blog Entries
So far in Blogtastic, the capability to actually add a blog entry has been suspiciously missing. This essential feature requires almost all of the techniques you've seen so far, hence the delay. You are now ready, though, so it's time to knock out this page. The page behaves in a similar way to previous pages that added content, but this page also includes a drop-down combo box that is used to select the category under which the entry is filed.
Create a new file called addentry.php and start the form:
Previously, you added the entire form first, but in this page, the very first form control will be the special drop-down box just discussed:
The drop-down combo box presents a visual box with a series of options that the user can select. This involves two basic steps. First, create a <select>
tag that contains the items within the box. Each item is housed within <option>
tags. In these tags, add the text that you would like to appear in the box (in this case, the category name) and a value
attribute. This contains the value that is passed when the user selects an item. Set this attribute to contain the ID of the category item.
In terms of making this work in code, the SQL query selects everything from the categories table. A loop iterates through the categories that are returned in the query. Within the while
loop, the <option>
tags are created, and the id
from the query is added to the value attribute.
Complete the rest of the form:
The form is shown in Figure 4-10.
Move to the beginning of the file and add the boilerplate introductory code:
Add the logic that actually processes the form:
This code creates an INSERT
query that is very similar to the ones on previous form-driven pages.
Finally, close the else block and add the footer.php code:
[previous] [next]
URL: