How to create a simple dynamic website with php and mysql

105

I have been posting tutorials from basic to advance levels. But recently when interacting with some my blog followers (still beginners) I found that they still have trouble doing basic stuff like connecting their php scripts with database. I have been getting many request from my blog followers for a simple php project, although I can’t solve every one issues but can certainly do my part. So this time I have made a mini project on how to create a simple dynamic website with php and mysql. You can download this mini project for free and customize it as per your needs and creativity.

View Demo

What is this simple website project with php and mysql?

In this mini project you will learn how to connect your database (mysql) with php, setup an html template, make header, footer, dynamic sidebar, fetch title, content, meta tags, meta description for dynamic web pages (individual pages). You can manage these web pages form the manage site area which is like the admin section of the website. You will also learn how to integrate facebook fan page, google badge plugin, and twitter follow button in the sidebar.

 

Folder and files used in this project

Take a look at the folder and files structure used in this project.

  • Manage Site – This is like an admin folder which contains files to create and view all the dynamic web pages of the website.
    • Cleditor – A light weight javascript library for UI text editor.
    • js – Admin area javascript files
    • home.php – Home page for the admin area
    • header.php – The header part of the admin
    • footer.php – The footer part of the admin
    • manage_pages.php – Manage all the pages that are created or to be created. delete pages from this section
    • add_edit_page.php – Add or edit a page here
    • tagline.php – Update website tagline here
  • libs – It contain configuration files, common functions and database connection script
    • common_functions.php – Commonly used function for the websites and admin area.
    • constants.php – Define constatant like table names, databasebe user access, site name
    • config.php – Database connection script.
  • js – It contains javascript files for the website.
  • images – Images for the website.
  • css – The stylesheet files for the website.
  • index.php – The home page of the website.
  • header.php – Dynamic header of the website.
  • footer.php – Dynamic footer of the website.
  • sidebar.php – Dynamic right sidebar of the website.
  • about-us.php – About us page.
  • contact-us.php – Contact us page with form.
  • category.php – Category page with sub pages.
  • page.php – A dynamic page that will load page content based on id.

Take a look at the database schema with sample records.

How to set up the project in your server.

Follow these steps to setup this project in your server:

  • Download the project zip file (link is available below).
  • Create a folder name simple-website under your htdocs/www folder.
  • In your phpmyadmin create a database named simple-website (you can give any other name too). Execute the SQL file database.sql in your database (remove create statement if you have already create a database).
  • Go to constants.php under libs folder. (libs/constants.php). Replace the database name in DB_DATABASE which your database name, add database username, hostname, passsword.
  • Also change the site URL (HTTP_SERVER and SITE_DIR)

 

Tips and tricks about the project.

There are some points that you need to remember and follow:

  • The table mp_pages has a field page_name it must be unique for every record. It means that every page must have a unique page name.
  • For the home page use index in the page_name field(mandatory), similarly for other pages like contact-us.php use contact-us(can be some other name ).
  • Pages can be created in two ways, (a) create a physical page with any name e.g. abc.php and then add/upload to your server. then add a database record with a same page which will have all the content, title and meta tags. (b) The other way is just to create a new page through database but with unique page name (this is used when you want pretty page url) and then the content will be called through their ids. like creating a page.php page and getting their contents, title (page.php?id=10).
  • To get a facebook like box plugin you need to create a facebook application first and then you can get the code from this link. If you are having trouble to create facebook application then read this tutorial which will help you in creating facebook application.
  • To get a google badge similar in the website. Go to google developers page. You will just need to replace your google plus/ page id in the url.

View Demo
Download
I hope this project will help you get started with php and mysql. Share your comments/feedback about this project.

Share.
 

About Author

Entrepreneur & Dreamer

I am a passionate Software Professional, love to learn and share my knowledge with others.

Software is the hardware of my life.

105 Comments

  1. Forbidden
    You don’t have permission to access /simple-website/ on this server.
    Apache/2.2.22 (Ubuntu) Server at localhost Port 80

    :/

  2. can u plzz tell me if i dont’t have MYSQL then can i connect database with MS ACESS?
    If yes then how can i do it??

  3. It is really a great and useful piece of info.
    I am glad that you simply shared this helpful info with us.
    Please keep us up to date like this. Thank you for sharing.

  4. i m creating a mini project using php-mysql and wamp server on online property selling and buying. could you give me the codes for it. only four to five forms are enough. pls

  5. Hello sir,
    Im fresher,i have interest in php.so please send one miniproject(creating dynamic website using php,mysql,html)to my mail.

    Thanking you

  6. hi.. thanks for this awesome tutorial.
    i have few questions : the link of page is not pretty like this simple-website/page.php?id=cGhwX0AjIUA= instead of simple-website/title-of-the-article.html
    how to hide Manage Site section from other than the admin ?

  7. Hey there I am so grateful I found your site, I really found you by
    accident, while I was browsing on Bing for something else, Regardless I am here now and would just like to say thanks a lot for a incredible post and a all
    round enjoyable blog (I also love the theme/design), I don’t have time to go through
    it all at the minute but I have book-marked it and also added your RSS feeds, so when I have
    time I will be back to read more, Please do keep up
    the excellent job.

  8. salam,
    how can i solve this please : Fatal error: Class ‘PDO’ not found in C:\AppServ\www\simple-website\libs\config.php on line 36

  9. Assalam o Alaikum!SIR,I HOPE U’ll be fine.I am glad to read ur tutorial.Dear Sir!I’ve no knowledge about php&mysql.I want to learn.So,Plz guide me and tell me how can I learn them..Allah Hafiz

  10. Dayanand Dhumala on

    The localhost page isn’t working

    localhost is currently unable to handle this request.
    500

  11. I get this error after installing simple-dynamic on my server

    The ololufe.com page isn’t working

    ololufe.com is currently unable to handle this request.
    HTTP ERROR 500

    Any help in this?

  12. Hi mate . Your works is great and thx for that . I have only one little problem . Can you please tell me how to make a new template for this script ?i add login script for admin area and is working fain . and i don`t have idea how to make a new template . can you please help me with that ? Thx .

    • Thanks mate. New template means new design.. if you just want to change the template.. just keep the pages as it is (pages structure and naming convention) and just try to change the code of the new template. You can get some free theme from this website https://w3layouts.com/

    • create a .htaccess file and write the code below, this may do it

      Options +FollowSymLinks
      RewriteEngine on

      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteRule ^(.*)\.html $1.php [L]

    • Try this mate maybe is ok 😛
      +++++++++++++

      RewriteEngine on
      RewriteBase /

      RewriteCond %{THE_REQUEST} (.).php
      RewriteRule ^(.).php $1.html [R=301,L]

      RewriteCond %{THE_REQUEST} (.).html
      RewriteRule ^(.).html $1.php [L]
      ____________________________________

      post after you really try
      P.S. it`s . htaccess file

      • Hi, can any one please help me out, I am facing issue with mod-rewrite urls.

        Website: onlinediscountcoupons.in

        I have created this website using the sample code provided by Mr. Software Guy. Please help me out

        My skype Id: prabhakar.seo

        Thanks

  13. bharath kumar on

    i am holding a website in that the database is missing ,so without data base we have to update that site

  14. Hi,

    Thanks for sharing this topic, Just wonder if there is any tutorial available for this, to make it better understandable

  15. i want simple project in php + Mysql
    I have 500 files stored in folder.
    I have 20 users and want to create login ID and password for each users.
    Each user after successfull login ID and password can accessm the file.
    At the same time a report shall be maintained showing which users access which files.

    OPlease provide support.

    Regrads

  16. after opening the website you will get the following error
    SQLSTATE[28000] [1045] Access denied for user ‘vpstejmf_vps’@’209.99.16.94’ (using password: YES).
    Would you please help me as I have to make my website live

  17. i have installed wamp on my friend’s laptop but …..
    Forbidden erro…. you don’t have premission on this server????? how to slove it…plzzz help me earlyyy as possible….

  18. hi ,
    i just want to know whether its necessary to install wamp server or one can directly download this project and upload the files on the server via ftp and then see if it works ..
    awaiting your reply

  19. hi,
    i just wanted to know whether it is required to download wamp server or one can directly download the files and upload them on the server?
    if yes which version of wampserver i need to download?

  20. Grace R.Doherty on

    I don’t even know how I stopped up here, but I assumed this submit used to be good.
    I do not realize who you are however certainly you
    are going to a well-known blogger should you are not already 😉 Cheers!

  21. In this tutorial I want to upload text and images combined into the page_desc field in database. How to do that.
    Thank for nice tutorial…

  22. First of all I want to say terrific blog! I
    had a quick question that I’d like to ask if you do not mind.
    I was interested to find out how you center yourself and clear your thoughts
    before writing. I have had a difficult time clearing my
    thoughts in getting my thoughts out there. I do enjoy writing however
    it just seems like the first 10 to 15 minutes tend to be lost just trying to figure out
    how to begin. Any ideas or tips? Thanks!

    • Hi. Thanks for appreciating my work.
      Well I can understand what you are going through, as I have passed the same phase. This is how i work. First of all before choosing any topic i just work on the problem and solution. some R&D and then I just write some dirty code until I achieve the solution I try to optimize it to bits. Now the final phase is where I put myself in users/reader shoes and think how simple and effective a tutorial can be if I had to read it. Also not to forget I switch off my cellphone and internet to keep away from distraction. Hope this helps you.

      Sorry for late reply, been busy with my startup nowadays.

  23. How do i start a project initially, for example a company need one type of project
    1.How to start or plan?
    2.and What are the information collect from their? [related to project]
    pls do help me sir

    I have selected 3 software company as a UI developer but immediately they give some project
    I don’t know how to start
    pls guide to me

    • 1. be focused
      2. learn as much as you can abt the project.
      3. get all the details you need for the project
      4. consult your seniors ( if any) to guide you from time to time.
      5. start developing section by section

  24. I’m amazed, I have to admit. Seldom do I come across a blog
    that’s equally educative and interesting, and without a doubt, you have hit the nail on the
    head. The issue is something not enough people are speaking intelligently about.
    I am very happy that I came across this during my search for something
    concerning this.

  25. SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘simple-website.mp_pages’ doesn’t exist

    error pls help

  26. I have created the database in PHPMyAdmin but it’s neither showing error nor showing content which is in database.sql on the website

  27. Hi. Am very new to this php development. Where to dump the downloaded php project in my system.Iam getting confused.Please let me know are there any open source platforms are there r not?

  28. hi shahrukh khan .. i have one doubt how to set fb login in my webpage …if the user login with fb and take name and email id in php..i will try many code but it not work… if you hlp me i want google+,fb login simple program in pdo php or nomal php

  29. Hi Shahrukh,
    Great blog post btw, however, was wondering whether I can integrate PHP into my own HTML website on my local server without having the actual website live. Also, I want to only update one certain part of my website just the main content area still don’t get how to do it using PHP and Ajax, if you have a solution to this please do let me know. Thanks

    • Hi Sharlene.
      If you have a local server running on your machine, just create a folder in you html website and dump all the files there, set that up in the config files and you are good to go.

  30. i have downloaded zip file of shopping website and i have already xammp installed in it and it works run the small php programs and how can in use it sir plz reply as soon as possible ….In last i want to wish u
    HAPPY EID

Leave A Reply

CommentLuv badge

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.