Already on ArticleSlash?

Forgot your password? Sign Up

Using PHP and MySQL to Develop a Simple CMS - Version 2

John Dixon
 


Visitors: 654
 1 vote

In version 1 of our simple CMS we introduced the following four files:

  • cms. sql
  • updatePage.htm
  • updatePage.php, and
  • index.php

Together, these files formed a very simple CMS.

In this article we'll extend the CMS slightly so that the database contents are extracted and presented in the form (UpdatePage.htm). This will make it easier to edit the contents, rather than simply overwriting them.

In order to make this modification, updatePage.htm needs to become a PHP file. I've called it editPage.php because updatePage.php already exists.

Here is the contents of editPage.php:

1. < html >
2. < head >
3. < title >Really Simple CMS< /title >
4. < /head >
5. < body >
6. < h1 >Really Simple CMS< /h1 >
7. < ?php
8. mysql_connect("localhost", “root", “password");
9. $result = @mysql_query("SELECT contents from cms. page");
10. while ($row = mysql_fetch_assoc($result)){
11. $contents = $row['contents'];
12. }
13. ? >
14.


15. Enter page content:< br >< textarea rows="10" cols="60" name="contents" >< ?php echo “$contents" ? >< /textarea >
16. < input type="submit" name="Submit" value="Update Page" >
17. < /form >
18. < /body >
19. < /html >

Most of this file is fairly simple HTML that doesn't need explaining. However, the following bits of code are probably worth discussing.

Lines 7 through to 13 contain PHP code to connect to the database and extract the contents of the web page.

Line 15 contains a tiny bit of PHP code to display the contents in the form's textarea. This line shows how easy it is to integrate bits of PHP code into lines of HTML code.

Remember though that in order to use PHP code in an HTML page, the file has to have an extension of .php. If it does not, the PHP code will not be processed by the web server.

Although very simple, the content management system described above could be used as the basis for a more substantial, and therefore realistic, CMS.

About the Author: John Dixon is a web developer working through his own company John Dixon Technology Limited The company also develops and supplies a free accounting-bookkeeping software tool called Earnings Tracker. The company's web site contains various articles, tutorials, news feeds, and a finance and business blog.

(408)

Article Source:


 
Rate this Article: 
 
MySQL recovery utility for any instance of corruption
Rated 1.0 / 5
based on 1 vote
ArticleSlash

Related Articles:

Develop a charismatic personality in 7 simple steps

by: Pradeep Kuma (April 23, 2009) 
(News)

CECT P168 Tri Band Version Versus the Quad Band Version A Comparison of the ..

by: Rae Edwards (June 18, 2008) 
(Communications/Mobile Cell Phone Reviews)

How to Develop Your Psychic Ability in 3 Simple Steps Without Drugs, Fakes Or ..

by: Tina Bardo (December 15, 2008) 
(Reference and Education/Psychic)

Basketball Coaches Develop a Positive Player Coach Relationship Following Just ..

by: Josh Stinson (June 17, 2008) 
(Recreation and Sports/Basketball)

Start to Develop Passive Income On the Internet with a Simple Money Making ..

by: Ben Frank (October 29, 2010) 
(Home Based Business)

The Use of PHP and MySQL

by: Helen Cox (July 02, 2008) 
(Internet and Businesses Online/Web Development)

Why Learn MySQL

by: Levi Reiss (September 26, 2008) 
(Computers and Technology/Software)

Migrating From Microsoft Access to MySQL

by: Oleg Fedorov (June 15, 2008) 
(Computers and Technology/Software)

SQL Server Hosting - MSSQL Vs MySQL

by: Lisa S Foster (February 05, 2010) 
(Internet and Businesses Online/Web Hosting)

MySQL recovery utility for any instance of corruption

by: Colin Dolly (February 15, 2011) 
(Computers and Technology/Data Recovery)