PDO step by step tutorial – Registration and login forms development

PDO - Registration and Login Form

This will be a straight forward step by step PDO tutorial for developing Registration and Login forms using mysql database.

Caution: In this post, I am not going to explain PDO or the benefits/uses of it. As, I’m sure, if you landed on this page, you already have good knowledge of basic terms.

This article will be really helpful for you if you are a university student and working on your final project OR if you are learning php now a days.

Step by step Guide for PDO registration form development

  • Open an editor to start writing your php code. I am using Eclipse.

Eclipse texteditor for web developers

  • Follow the below basic code, to connect database.

Basic PDO code

 

Note: If you don’t have any database yet, or want to create new db. Go to: http://localhost/phpmyadmin/

Click New to create a new database using mysql

Click “New” to create a new database from phpMyAdmin.

  • Successful connection establishment result will be as follows:

Result of basic PDO code

  • As shown in the above screenshot, you have to goto localhost/foldername/yourfilename.php In my case, I have created the folder AU (For AustraliaUnwrapped) and file name is index.php

If you are a new coder, your first working code will give you BIG happiness ha ha

Creating Users Table

Let’s check the database part now.

Create a table “users” with required number of fields. Suppose, I need 7 fields. Such as, Users ID, username, email, password, First Name, Last Name, and City.

You can decide, what information you want to fetch and store. You can ask DOB etc. too.

Here is my table’s screenshot

Creating table in mySQL database

 

Create a simple HTML Form

Create a simple HTML Form for your required fields.

Here is mine:

HTML registration form code

Result:

PDO registration Form Output is as follows:

PDO registration Form Output

 

Here is the complete PDO for above screenshot:

PDO Code for registration form

If you have any questions, feel free to ask in comments 🙂

  • Go back to line 4 for placing if condition. So, we can add function for register button. Such as if register button clicks, what should happen?
  • The attached database should store the data, agree?

Here is the complete source code for your consideration. As it was about PHP only so not enough CSS inserted.

Download Here!

In this source file, you will get 3 different code files. One for main index page, 2nd for profile page and 3rd for logout page.

Read the code and ask questions if you have any.

This is the most simplest code, in which we we are fetching data from using registration form and storing it into database. As, we have established database connection.

Once, User get registered. He/she can get login by using correct info. Finally, there is logout link too.

 

Leave a Comment

*

/* ]]> */