Learn PHP MySQL in 2 Days : Day 2 of 2

Learn PHP MySQL in 2 Days


I will explain with code in Day 2. Here I have created one application for all.  My First PHP Sample Application is contains following pages:

index.php : This Page is home page to login user with available username and password.

page2.php : This page will verify  username and password which is passed from the index.php page and will verify with database and if it is correct you need to redirect user to some page and if it is wrong you need to redirect user back to index.php page for asking userid and password again.

home.php : This page is home page for the logged in users. If user passes valid userid and password then he/she will be redirected to home.php page. This page is also having some menu for user operations.

changepass.php : This page is added so that use can change their password.

changepass2.php : This page will receive password from the changepass.php and verify against database with existing one if current password is Same it will change password with new one,  and will redirect again back to changepass.php page.

profile.php : This page is to display profile details to user and user can also change their details using the same page.  Here another feature is important that it also fetches current information from the database as per the active session.

profile2.php : This page is act same as changepass2.php but here it will change profile details of users.

logout.php : This page is used to destroy session and redirect user back to index.php page.

Note: This code is only for beginners to learn PHP. There are new version of code available in PHP like object based that is suggested for Live Websites.


 Now Let Start with Actual Coding with PHP

Here I have to take few assumptions:

  • Database : MySQL
  • MySQL Database Name: fdp
  • MySQL Database Username : root
  • MySQL Database Password : root

Step 1 : Create Database using phpmyadmin or from command prompt

(DatabaseName : fdp)

MySQL Database Query :

Step 2 : Insert few records or execute following query.

 Sample Insert Query :

Step 3 : Create all following files and put it on Server and after execute it.

(Hint for WAMP Users : Save to www\fdp folder : url to run: http://localhost/fdp)

(Hint for XAMPP Users : Save to htdocs\fdp folder : url to run: http://localhost/fdp)

 index.php File Code

index.php Screenshots

Index Page

page2.php File Code

 home.php File Code

Home Page Screenshots

Home Page


 profile.php File Code

Profile Screenshots


profile2.php File Code


changepass.php File Code

 changepass Screenshots

Change Password

 changepass2.php File Code


logout.php File Code

 Logout Screen Shots


Hope this code will help you.  for feedback / suggestions / error kindly send email via contact us page.

Adarsh Patel

My Self Adarsh Suryakant Patel. Currently I am working as Assistant Professor at Parul Instiute of Engineering and Technology, MCA Department, Limda, Vadodara. Major Responsibility : * Lectures * Organizing Training and Expert Sessions for * Placement and Recruitment * Faculty Representative