spot_img

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

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

spot_img
Kelly W
Kelly W
Dream big, play hard, take the wins and embrace the losses.
spot_img

1 COMMENT

Stay Connected
41,936FansLike
5,721FollowersFollow
739FollowersFollow

Read On

spot_img
spot_img

Latest