Creating Registration Form with PHP and MySQLi

Creating Registration Form with PHP and MySQLi

In previous post we have learned to create a secure login system with session. Now let’s have look at How to Create a Registration Form with PHP and MySQLi. Well it’s quite easy and can be use for different purposes. It can be use to Register a new member on your membership website or you can use it to get some inputs from the user for further processing, well it doesn’t matter for what you want a registration form the code is same for all just need a little bit knowledge of PHP and MySQLi you can create your own one. Here I am going to explain each and everything for registration form, but still you can start a discussion below if you need any type of help or you are confuse at any point.

DOWNLOADDEMO

So, first we need a HTML form that include some input fields and a submit button.

Then move to PHP code. As we are working with PHP and MySQLi. So, definitely we need to connect our page with database. Here is the database structure:

Now, connect your PHP Code with MySQL Database.

db.php

Now, we need to perform registration process when user hit ‘Register’ button. For this purpose we will use PHP isset() function as:

Under this if statement we will perform all our actions. First we will use mysqli_real_escape_string() function escape special character in a string to for use in an SQL Statement. It also help us to prevent from SQL Injection Attack.

md5() is a PHP fucntion, used for password protection. It encrypt data entered by the user and store in special format that can’t be decrypted. You can read more about md5() from here.

OK, it was basic structure for our PHP Code. Now lets move towards actual code. When user entered his email, we need to check it this email already exist or not. If it exist then it will print error “Sorry…This email already exist…“. Here is how we can check email.

What does this code will do? First it will perform MySQLi query to check all rows in database. If it found entered email in database it will print out error of already existed email otherwise it will insert user record in database by using the following code.

That’s all! Now you have your own Registration Form. You can use it for different purposes depends on your requirement.

DOWNLOADDEMO

14 Comments

  1. Umar Rauf November 17, 2015
  2. Umar Rauf November 17, 2015
  3. Abdullah Majid November 17, 2015
  4. Umar Rauf November 17, 2015
  5. she2796 November 18, 2015
  6. Umar Rauf November 18, 2015
  7. karthik January 24, 2016
  8. michael February 12, 2016
  9. michael February 12, 2016
  10. [email protected] May 8, 2016
  11. Abdullah Majid May 8, 2016
  12. sEiNZu June 1, 2016
  13. Catalin October 19, 2016

Leave a Reply