PHP MySQL Registration form with validation

By | August 2, 2017

Registration is a common process when you want to create an account under your name. Whenever you visit famous websites like Facebook, Gmail, you must register and create a profile if you want to make use of their services. Today we will understand how the registration process works and how to build a registration form using MySQL database. This PHP MySQL Registration form is validated using javascript. If you want to learn how to build a login form in PHP using MySQL, please follow this link.

Salient points about this Registration form:

  • Inputs are validated using Javascript.
  • The registration form is styled using an external style sheet.
  • Only PHP 7.0 supported methods are used. Most of the old methods are discontinued from PHP 7.0.
  • The password has been encrypted using password_hash() method while inserting it into MySQL DB.
  • It makes use of prepared statements while inserting the records into the database. Prepared statements are executed fast, very useful against SQL injections/attack, and also, minimize the bandwidth to the server.

Before we begin with the coding part, let me explain how to execute this PHP code.

  1. Download and install wampserver (WAMP) software, if you are using windows OS. You can go for a LAMP if you are using Linux based OS. Once the installation is completed, start the WAMP server.
  2. You must see a wamp server icon in green in your task bar by now. Click on the icon and go to MySQL -> MySQL console. Execute the following script to create a database, followed by which a table.


    How to use WAMP server to execute your MySQL script
  3. Next, copy all the files (RegisterForm.php, Style.css, Register.php, RegSuccess.php, DBConnection.php) into the WWW directory of the WAMP server. You are almost done now.
  4.  Next, once again go to the wampserver icon and click on the localhost. This will take you to your default browser where you will get to see all the files placed under WWW directory. Select RegisterForm.php file to see the registration form as shown in the below image.
PHP MySQL Registration form with javascript validation

Registration form

 

 

 

If the records are inserted into the profile table successfully, you will be taken to the success page.

Registration form in PHP using MySQL

 

You can now, query the profile table to check for the inserted records. The following image shows the record inserted for the user John and you can take a look at the password column to notice that it is present in the encrypted format.

Password encryption in PHP registration using MySQL

Record inserted successfully

Hope you enjoyed this. Let me know your views on this or doubts if you across any. Once you are done with the registration, I recommend you to follow how to build a login form in PHP.




Author: Ravi Bandakkanavar

A Techie, Blogger, Web Designer, Programmer by passion who aspires to learn new Technologies every day. It has been 6 years since I have been publishing articles and enjoying every bit of it. I want to share knowledge and build a great community with people like you.

Suggested articles for you:

6 thoughts on “PHP MySQL Registration form with validation

  1. beni

    Parse error: syntax error, unexpected ‘RegSuccess’ (T_STRING), expecting ‘,’ or ‘)’ in C:\xampp\htdocs\Register.php on line 21

    I’m getting the above error…

    Reply
    1. Ravi Bandakkanavar Post author

      Hi Beni,

      RegSuccess.php is a file which will get called after successful records insertion into the database.
      Can you confirm if you are using the same Register.php file?

      Reply
        1. Ravi Bandakkanavar Post author

          Beni,

          Can you tell me what is there on line 21 in your Register.php?

          It’s something to do with quotes or ‘) or ‘;’.

  2. Hemanath K

    [06-Aug-2017 16:12:46 Etc/GMT] PHP Warning: mysqli_connect(): (42000/1044): Access denied for user ‘fdhubin_admin’@’localhost’ to database ‘fdhubin_HR’ in /home/fdhubin/public_html/itdigitalhub.com/DBConnection.php on line 7
    [06-Aug-2017 16:12:46 Etc/GMT] PHP Fatal error: Uncaught Error: Call to a member function prepare() on boolean in /home/fdhubin/public_html/itdigitalhub.com/Register.php:13
    Stack trace:
    #0 {main}
    thrown in /home/fdhubin/public_html/itdigitalhub.com/Register.php on line 13
    [06-Aug-2017 16:12:46 Etc/GMT] PHP Warning: mysqli_connect(): (42000/1044): Access denied for user ‘fdhubin_admin’@’localhost’ to database ‘fdhubin_HR’ in /home/fdhubin/public_html/itdigitalhub.com/DBConnection.php on line 7
    [06-Aug-2017 16:12:46 Etc/GMT] PHP Fatal error: Uncaught Error: Call to a member function prepare() on boolean in /home/fdhubin/public_html/itdigitalhub.com/Register.php:13
    Stack trace:
    #0 {main}
    thrown in /home/fdhubin/public_html/itdigitalhub.com/Register.php on line 13

    i am getting above error

    Reply
    1. Ravi Bandakkanavar Post author

      Hi Hemanth,

      It clearly says that an error while connecting to the database – fdhubin_hr for the user fdhubin_admin. You can recheck your database credentials.

      Reply

Did it help? Comment here..