Online Book Reader

Home Category

HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [361]

By Root 1507 0
”>

Here’s the cool thing about dbCMS. This page is all you need! You won’t have to copy it ever. The same PHP script is used to generate every page in the system. If you want to change the style or layout, you do it in this one script, and it works automatically in all the pages. This is exactly how CMS systems work their magic!

Looking at all the code at one time may seem intimidating, but it’s quite easy when you break it down, as explained in these steps:

1. Pull the pageID number from the request.

If possible, extract the pageID number from the GET request. If the user has sent a particular page request, it has a value. If there’s no value, get page number 1:

//get pageID from request if possible

$pageID = $_REQUEST[“pageID”];

$pageID = mysql_real_escape_string($pageID, $conn);

if ($pageID == “”){

$pageID = 1;

} // end if

Don’t forget to escape the pageID data! Whenever you extract data from a page to use in a query, remember to escape the data to prevent injection attacks.

2. Query pageView to get all the data for this page.

The pageView view was designed to give you everything you need to build a page with one query.

If you’re using MySQL 4 (without views), just copy the query from the view definition and insert it into your PHP code. The view is just a shortcut — it’s never absolutely necessary.

3. Pull values from the query to populate the page.

Look at each response of the query. Then, look at the block value to see which type of query it is and populate local variables:

//read current page information from the db

$conn = mysql_connect(“localhost”, “xfd”, “password”);

mysql_select_db(“xfd”);

$sql = “SELECT * FROM pageView WHERE pageID = $pageID”;

$result = mysql_query($sql, $conn);

4. Write out the page.

Go back to HTML and generate the page, skipping into PHP to print the necessary variables.


Allowing user-generated content

The hallmark of a CMS is the ability of users with limited technical knowledge to add content to the system. My very simple CMS illustrates a limited way to add data to the CMS. Figure 5-4 shows the buildBlock.html page. This page allows authorized users to add new blocks to the system and produces the output shown in Figure 5-5.

Figure 5-4:

A user can add content, which updates the database.

Figure 5-5: The result of a successful page update.

After a few entries, a user can build a complete second page, which might look similar to Figure 5-6.

Figure 5-6: This page is simply another set of page blocks added by the user.

The system is simple but effective. The user builds blocks, and these blocks are constructed into pages. First, look over the buildBlock.html page.

Build new block

type = ”text/css”

href = ”csStd.css” />

Build a new block

method = ”post”>

password

name = “password” />

Return Main Page Previous Page Next Page

®Online Book Reader