PDO Step by Step Tutorial – Registration And Login Forms Development

Step by Step Guide for PDO registration form Development

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 nowadays.

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 a 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


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 the 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 a 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 are fetching data from using the registration form and storing it into the database. As we have established a database connection.

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

Main Image Source : Pixabay

Also See : How to Create a Document People Actually Want to Read

Forms in PHP – PHP Form example with Database

Kelly Wilson

“If you tell the truth, you don't have to remember anything.” ― Mark Twain I am what could be considered a truth seeker, a news reported, or even to some a story teller. My version of the truth is what you will read. Its up to you to form your own version of truth. Respect Kelly

Leave a Reply

Your email address will not be published. Required fields are marked *