Hello readers, Today in this blog you'll learn how to create a Login & Signup Form with Email Verification using PHP and MySQL. Earlier I have shared a blog on How to configure XAMPP to send Mail from Localhost in PHP? If you haven't still read this blog, then I want to suggest you first read that blog and continue this because in that blog I've taught you how to configure XAMPP before sending mail from the localhost.

As we all know, the login and & Signup Form is the set of different input fields - Name, Email, Username, Password, etc. which are used to authenticate users before giving access to the site. In our program [log in & Signup Form with Email Verification], there are eleven PHP files and one is a CSS file means there are a total of twelve files in our user name folder.

Login & Signup Form with Email Verification using PHP and MySQL

At first, on the webpage, there is shown only a login form and inside the login form, there is signup now link to redirect the user to the first signup before login. When the user tries to log in without even signup the form, there is displayed an error message labeled as "It looks like you're not yet a member! Click on the bottom link to signup".

In the signup form, while the user is signing up, if he enters the same email, which already exists in our database then there is displayed an error message labeled as "Email that you've entered is already exist!". And when the user doesn't match two password combinations, there is also displayed an error message labeled as "Your confirm password not matched".

When the user filled up all the required inputs correctly, then a six-digit verification code number is sent to the user email and he will be redirected to the OTP Verification page. If the user entered the wrong code, there is displayed an error message labeled as "You've entered incorrect code!". If the user exit the OTP verification code page without entered valid or correct verification code and come to the login page to log in with the same email and password which he used to sign up, then he will be again redirected to the OTP page and there is displayed an info message labeled as "It looks like you've not verified your email".

When the user entered the correct verification code, then he will be redirected to the Home Page. On the home page, there is a navbar with a logo on the top left corner and the logout button on the top right corner. At the center of the home page, there is a welcome message with the name of the user which he entered while signing up the form. And when the user clicked on the logout button, he will be redirected to the login page and at this time he can log in with their correct email and password and will be directly redirected to the home page without redirecting to any other page.

If you're feeling difficult to understand what I am saying. You can watch a full video tutorial on this program (Login & Signup Form with Email Verification).

Video Tutorial of Login & Signup Form with Email Verification



To create this program (Login & Signup Form with Email Verification). First, you need to create twelve files - login-user.php, signup-user.php, controllerUserData.php, user-otp.php, home.php, logout-user.php, connection.php, forgot-password.php, reset-code.php, new-password.php, password-changed.php, and style.css. You can also download all the source code files through the given link. Click here to download source code files.

Remember that, after downloading source files or pasting the following codes, you've to create a database, table, and six columns inside the table. The name of the database must be userform, table name must be usertable, and inside this table, you've to create six columns.

Columns name:

id type int(11) auto_increment
name type varchar(255)
email type varchar(255)
password type varchar(255)
code type mediumint(50)
status type text

Before pasting these codes, please watch this blog How to configure XAMPP to send Mail from Localhost in PHP? because without configure the XAMPP server to send mail using PHP, you won't send mail and there is no meaning to paste these given codes.

Fixed: Users can access the Home Page from the otp-user.php and reset-code.php pages without entering the correct otp code.

Note: Due to the many PHP file links in the codes, I got multiple errors while uploading this post. So I commented all the link tags (<a>)  and I recommend you download the source code files from the above link instead of copying codes. Otherwise, you need to uncomment all commented <a> and <title> tags.

connection.php file:


login-user.php file:


signup-user.php file:


controllerUserData.php file:


user-otp.php file:


home.php file:


forgot-password.php file:


reset-code.php file:


new-password.php file:


password-changed.php file:


style.css file:


Thanks for visiting, Keep visiting.


70 Comments

We welcome relevant and respectful comments. Off-topic or spam comments may be removed.

  1. whats next after creating the table

    ReplyDelete
    Replies
    1. Create the php files and paste the following codes.

      Delete
  2. Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\200\controllerUserData.php on line 19

    where is the mistake?

    ReplyDelete
  3. i include all the files to a html file but nothibg works. how to make them works ??

    ReplyDelete
    Replies
    1. Please learn some basic php before pasting these codes. You've to create php files not html files.

      Delete
  4. hi can you make a video on how to connect thise codes and how to create a server like that reply me the link of the
    thank you

    ReplyDelete
  5. dude i want to add a city and institution also in registration form but i cant store values in the database

    ReplyDelete
    Replies
    1. What's the error you're facing while inserting data's into database?

      Delete
  6. its saying failed to insert data into database

    ReplyDelete
    Replies
    1. Database error please check the name of your database with the connection.php file.

      Delete
  7. good job
    What is the step to take after downloading the files and programming Xampp ? Where should I place my php file in " How to configure XAMPP to send Mail from Localhost in PHP ?"

    ReplyDelete
    Replies
    1. After downloading files just create a database, table, and columns with that names which are mentioned above and to configure XAMPP read this blog - https://www.codingnepalweb.com/2020/09/how-to-configure-xampp-to-send-mail-from-localhost-in-php.html

      Delete
  8. Can you please provide direct link of files becaz when i click link the timer did,nt start helo me sir!!

    ReplyDelete
    Replies
    1. I'm sorry for that and now it has been fixed. Please download again from the same link.

      Delete
  9. my thing im working on only uses html is there a way to do this on html? like save the data?

    ReplyDelete
  10. and when i press the login button or the sign up botton it sends me to an error screen :o

    ReplyDelete
  11. can u plz make one tutorial for phpmyadmin??

    ReplyDelete
  12. Thank you codingnepal amazing help

    ReplyDelete
  13. it doesnot send any email please help me

    ReplyDelete
  14. Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 78sm5550625pfz.211 - gsmtp in C:\xampp\htdocs\Login and Signup Form with Email Verification - PHP\controllerUserData.php on line 33 (Failed while sending code)


    where the last php file should be save and with which name plz specify.

    ReplyDelete
    Replies
    1. Create a php file inside the HTDOCS folder with .php extension and paste the following codes in this file then put the receiver email and sender email address in the mentioned fields.

      Delete
  15. How do i upload the files i donwloaded to Adobe Dreamweaver?

    ReplyDelete
  16. Replies
    1. I've shared all required things in this blog. Please read carefully.

      Delete
  17. im a beginner complete beginner to php so just a question why isnt their any .html files like how would i see the form if theirs only .php files

    ReplyDelete
    Replies
    1. You've to install server to run .php file. You can google it for more info.

      Delete
  18. Can you share the source code of your website ??
    It looks very attractive and easy to use.

    ReplyDelete
  19. What did you used ? blogger or wordpress for this site .

    ReplyDelete
  20. show form verify but no see code in email help me plz

    ReplyDelete
  21. Sorry, failed while sending mail!
    why ?
    what should be writ in receiver and sender in send_mail.php?
    help phz i writ every thing you do

    ReplyDelete
  22. Hii,
    i have one error when i register new account it shows

    "Failed while inserting data into database!"
    i had check my database name but its correct so where is problem.
    please help me to solve this error

    ReplyDelete
  23. How to add push notification which says codingnepal wants to send you notification 1.allow 2. No thanks .
    Please give code for that

    ReplyDelete
  24. Failed while sending code!
    I was trying to implement it in my hosting .But I am getting this error. But data perfectly saved in database,since I changed few necessary changes to connect with my hosting databases.Now my question is why I am facing this error?
    please help me and thanks a lot for this great tutorial.

    ReplyDelete
    Replies
    1. It's maybe there is some mistakes on variables, database name or something else.

      Delete

Post a Comment

We welcome relevant and respectful comments. Off-topic or spam comments may be removed.

Previous Post Next Post