Posts Tagged ‘Develop’

Using Php and Mysql to Develop a Cms

Sunday, May 2nd, 2010

In this article I’ll try to describe how to develop a very simple Content Management System (CMS). I’ve chosen PHP as the server-side scripting language and MySQL as the database management system purely because I think they are fairly easy to use and they do the job very well.

I won’t spend any time describing CMSs, what they are, or why you should or should not use them as there are plenty of excellent articles around that describe them perfectly well. I’ll just explain one way of developing a CMS.

This CMS consists of a single web page (index.php) that can have its contents updated by use of a form (editPage.php). The contents entered via the form are stored in a database, and are accessed and displayed by the web page. Although this CMS is too simple to be of any real use, it could be used as the starting point for a real life CMS solution.

There are four files in this project:

cms.sql
editPage.php
updatePage.php
index.php

cms.sql
This file creates a database called cms, and creates a table in that database called page. It also loads some intial data into the table. You only need to use this file once.

editPage.php
This web page contains a simple form that can be used to enter (and edit) the contents displayed by index.php.

updatePage.php
This is the form handler – the script that processes the data (entered in editPage.php) and inserts it into the database table (page).

index.php
This is the web page that displays the data held in the database table.

cms.sql

1. CREATE DATABASE cms;
2. USE cms;
3. CREATE table page (
4. pageID integer auto_increment,
5. contents text,
6. primary key (pageID)
7. );
8. insert into page (pageID, contents) values (’1′, ‘dummy text’);

Line 1 creates a database called cms in the MySQL database management system.

Line 2 tells MySQL to use the database for the subsequent commands.

Line 3 creates a table in the database.

Line 4 creates a column called pageID, which will contain integers, and which will be automatically incremented as new records are added to the table. As we only have one web page (index.php) in our imaginary website, we will only have one record and therefore one integer: 1. If we added additional pages to the table, they would be automatically numbered (2, 3, 4, etc).

Line 5 creates a second column called contents, which will contain text. This is where the editable contents displayed by index.php will be stored.

Line 6 sets pageID as the primary key, which you can think of as a reference for the table. As we only have one table, which will contain only one record, we won’t make any use of the key. I’ve included it though because it’s good practice to do so.

Line 7 simply closes the bit of code that was started in line 3.

Line 8 inserts some intial data into the table: 1 as the first (and only) pageID, and ‘dummy text’ as the contents of the first record.

editPage.php

(Note that for display considerations, I’ve used square brackets ‘[' instead of angle brackets for tag names.)

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']; // Do not change these to angle brackets
12. }
13. ?]
14. [form name="form1" method="post" action="updatePage.php"]
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.

updatePage.php

1. [?php
2. $contents=$_REQUEST['contents']; // Do not change to angle brackets
3. mysql_connect(”localhost”, “root”, “password”);
4. $result = @mysql_query(”UPDATE cms.page SET contents=’$contents’”);
5. mysql_close();
6. ?]

This is the form handler, that’s to say, the script that processes the data entered into the form (in editPage.php).

Line 1 signifies the start of a PHP script.

Line 2 requests the contents that were posted from the form. We could have written
$contents=$_POST['contents']; instead if we had wanted to.

Line 3 connects to the MySQL database server, setting up the host name, which I’ve assumed to be localhost, the database user, which I’ve assumed to be root, and the password needed to connect to the database. Naturally, I have no idea what this would be for your system so I’ve just written the word password.

Line 4 updates the page table in the cms database with the new contents.

Line 5 closes the database connection.

Line 6 closes the PHP script.

index.php

1. [html]
2. [head]
3. [title]Home Page[/title]
4. [body]
5. [h1]Home Page[/h1]
6. [?php
7. mysql_connect("localhost", "root", "password");
8. $result = mysql_query("select contents from cms.page");
9. while ($row = mysql_fetch_assoc($result)){
10. $contents = $row['contents']; // Do not change to angle brackets
11. }
12. echo $contents;
13. ?]
14. [/body]
15. [/html]

This is the web page that displays the contents from the database.

Most of the lines in this web page are pretty straight forward and don’t need explaining. Lines 6 to 13 contain the PHP script that extracts the contents from the database and displays (echos) it in the browser.

Installing/Running the CMS

To use the CMS you need to copy the files onto your web server into the area allocated for web pages. Your web server needs to support PHP and MySQL; if it doesn’t, the CMS won’t work.

You also need to use the correct database connection names and passwords (those used in the mysql_connect lines in the PHP scripts).

Exactly how you run the cms.sql file to set up the database and database table will vary from web server to web server so it’s difficult to give precise instructions here. If you have a phpMyAdmin icon or something similar in your web servers control/administration panel you should be able to use that.

Once you’ve set up the database and table, you can simply browse to the editPage.php web page and update the database contents. You can then browse to the index.php page to view the updates.

  • Share/Bookmark

i want to develop a website do i need to pay for my Domain name & Space Annually or once?

Sunday, April 4th, 2010
  • Share/Bookmark

How can i develop a simple iPhone app on Microsoft Windows environment PC?

Saturday, April 3rd, 2010

How can i develop a simple iPhone app on windows environment PC? Virtual hosting of Mac OS etc or web based Mac OS environment would do…Please suggest some reliable options

  • Share/Bookmark

How to Choose Proper Web Hosting to Develop Your Online Business

Friday, March 5th, 2010

Nowadays several web hosting company scattered at every lane in any reputed city. The growth in web hosting business is recognizably increased within previous few years. Currently numerous web hosts are offering wee web hosting packages to start up your online business.

For new people in web world (who wish to start their online business for their own firm) is really pretty tough to choose the proper web hosting company amongst to the several web hosts. Near about every web hosting company offering reasonable pricing for same kind of hosting plan, thus arise the need for appropriate selection of selecting a proper web hosting company.

This conclusion is really worth for your internet business. Suppose you have already chosen your hosting plan, it may be Linux hosting or Windows hosting plan. But whom you choose to deliver the service? Are they having previous track record to do that efficiently?

When you chosen your hosting plan, then quickly visit some reputed top hosting concerns and take a gaze at their hosting features. Are these following features they have as a trendy web hosting company?

1. Professional by nature and ethically accountable.

2. Aware form surroundings and best client support. The assurance to consumers must be done efficiently.

3. Endorse optimistic attitude and offer exceptional support services. Authentic web hosts must beat their assurances that made previously.

4. They should have 24/7 support facility as when client feels any problem they will instantly ready to solve them.

5. They should sensible and realize their consumer needs before final deal. An ethical web host should be honest about what they can provide and what they cannot offer.

6. They should put you on the right track of their web hosting offers and don’t ever try to impress you unnecessarily with some fake assurances.

7. That web hosting company must be reputed, well known and continuously modernize their latest features or new technologies to their customers.

8. Ideal hosting firms must try to continue best relationship with their consumers. Thus they highly satisfied their clients with their best web hosting services.

9. An honest web host simultaneously advice you to use all their provided features what infused within your selected hosting plan.

10. The web host should not believe on immediate profits because if their provided service is absolute then they know profit is gained automatically. They more concentrate to their service and promises.

11. An efficient web host should have a pool of dedicated member to deliver their service superbly.

These are some few important considerations before you chosen your hosting service for your online business. You should check their market reputation and how longer they are providing web hosting service as well. Verifying their current customer list is also a fine way to ensure their product quality and market consistency.

Don’t concentrate only on costing factor, because expenditure of a web hosting plans has been reduced by every year due to market competition. Ultimately visit some famous web hosting forums to discus your questions with others. Don’t go with their suggestions, because you only need to gather more knowledge about web hosting from it.

  • Share/Bookmark

What is the best way to develop a personal web site with your own domain name?

Friday, February 19th, 2010

I am most interested in web hosting. I don’t mind paying for the service but I do want reliability and value.

  • Share/Bookmark

www.teranor.com – Websites for free, design and develop of internet sites for FREE. All kind of sites.

Tuesday, February 16th, 2010


www.teranor.com – We professionally design and develop all kind of site totally for free if you host your site with us. Each site takes us around 2 weeks. See the details on www.teranor.com

  • Share/Bookmark

Domain Name Hosting Solutions – Develop Your Domain Names into Websites

Sunday, February 14th, 2010


Every great website starts with an idea, and you can bring your innovations online with Webfusion at webfusion.com From registering your domain name to building your custom web application, our platform makes it easy to develop a custom site with complete database access, secure web e-mail solutions and plenty of transfer space for both Linux and Microsoft hosting accounts.

  • Share/Bookmark

How to Develop That New Domain Name You Want to Buy for Under $10

Saturday, February 13th, 2010

Do you have a good domain name you want to buy, but either don’t have the time or just don’t have the capitol to develop it right now? Well here’s an idea to get free hosting and to develop your domain for the cost of a domain name, and possibly earn a little revenue while you’re at it.

Want to see a good example of what your new site might look like when you’re done? Go to Instantdeals.com. I used the same idea to develop this domain.

Here’s what you do. Go to my secure domain name reseller store and buy that available domain name you’ve been wanting to purchase. Or you can use your own registrar if you have one. Next go to WhyPark.Com and sign up for their free account. Once you’ve been approved, go back to my domain name reseller store or your registrar if you bought your domain name some where else, log in, and change the nameservers for your domain name to point to NS1.WHYPARK.COM and NS2.WHYPARK.COM.

If you’re not sure how to change your nameservers I have more detailed information at Instantdeals.com.

Now go back and log in at WhyPark.Com, follow the instructions to add your site. And that’s it. After familiarizing yourself with WhyPark.Com you can add text links and content to your site like I have done at Instantdeals.com.

You can also earn revenue from whypark’s ad network which is generated automatically when you add your site. Or for a small fee you can use a third parties ad network like google adsense. Make sure you read their FAQ and Terms of Use before you begin advertising your new web site.

Happy developing and good Luck!

  • Share/Bookmark