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's 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 a 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.


147 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. Please share file database.sql

    ReplyDelete
    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
  25. Hi CodingNepal, on my computer it is not working, do u have a IDE for the PHP?

    ReplyDelete
    Replies
    1. You have install XAMPP server to run php file.

      Delete
  26. Nice Job! But I have a problem it says "Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\controllerUserData.php on line 33" My code is the same as yours |Failed while sending code!" Can you help me?

    ReplyDelete
    Replies
    1. You have to configure you XAMPP, please read this blog properly.

      Delete
  27. Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 22sm22663187pfn.190 - gsmtp in C:\xampp\htdocs\Login and Signup Form with Email Verification - PHP\controllerUserData.php on line 33

    what should i do sir. please help

    ReplyDelete
  28. Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\XAMPP1\htdocs\loginform\controllerUserData.php on line 33
    Signup Form

    ReplyDelete
  29. is don't work for but y say fail to connect database can you help me pls

    ReplyDelete
    Replies
    1. Please create database and table name with the mentioned names.

      Delete
  30. Failed while inserting data into database! help me pls

    ReplyDelete
    Replies
    1. Please create database name and table name with mentioned names.

      Delete
  31. how can you enable localhost on chromebook

    ReplyDelete
  32. My browser is taking forever to download the source code. Infact, it is just showing "The file will start downloading in 30 seconds time", but nothing happens after the said 30 seconds.

    Another thing, do you have a tutorial on how to auto arrange popular Posts using post hits/visits, and configuring social media sharing buttons

    ReplyDelete
    Replies
    1. Can you please tell me in which blog post you get this problem so I can solve it.?

      Delete
  33. when i try to sign up...Fail while sending code appear..pls help

    ReplyDelete
    Replies
    1. Make sure you have configured you XAMPP and google account properly.

      Delete
  34. Warning: mail(): Failed to connect to mailserver at "localhost:8080" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\TDM202\gr\controllerUserData.php on line 33

    ReplyDelete
  35. Warning: mail(): Failed to connect to mailserver at "localhost:8080" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\TDM202\gr\controllerUserData.php on line 118

    ReplyDelete
  36. Hi, I have been getting this errors this errors frequently "Failed while inserting data into database!"

    I think The problem is from the data_check, I have tried selecting before inserting, but unto no avail, kindly help check the code again. Thanks

    ReplyDelete
    Replies
    1. This error mainly shows if your database, table, column names not matched with your coding php files. So please check it.

      Delete
  37. Thank you for your great work. It's very perfect until the forgot-password & resend code. Could you explain how to make it work?

    ReplyDelete
    Replies
    1. I've added forget password link also..please download files and check it.

      Delete
  38. Bro You Might like wala Section main Ads nhain Lag raha kindly help me. ADS kis trha lagaon

    ReplyDelete
    Replies
    1. Bro thoda theme me jake html ka code me change karna padta he...Instagram pe contact karo batadunga.

      Delete
  39. bro I want ask you if you are familiar wit javascript and php if you have time of course abut a little trick I don't know how to do it

    ReplyDelete
    Replies
    1. Bro there are no tricks...It's all about learning bro.

      Delete
  40. how to connect gmail with code on 000webhost

    ReplyDelete
  41. I didn't received the email verification. I already configured xampp server. do I need to change the email from the code with email that I used when configured xampp?

    ReplyDelete
  42. how to solve this problem
    "Failed while sending code!"

    ReplyDelete
  43. Bro makes a tutorial about mobile phone verification. Please bro

    ReplyDelete
  44. hi bro
    please do video on user id generation(id=10001) generation and login with there userid

    ReplyDelete
  45. Amazing site I have never visited like your site that working for others without ceasing thank you alot.

    ReplyDelete
  46. Hi!
    Have you posted the video "How to configure XAMPP" on youtube yet.
    If yes please send me the link cuz i can not find it.

    ReplyDelete
  47. It is saying failed while sending code! What to do?

    ReplyDelete
  48. I have a question. Is this method safe ?

    ReplyDelete
  49. Hi, i do have a question.
    How long does it take to get the verification code posted into my email?

    Thnx so much beast!

    ReplyDelete
  50. thank u.... but now how i can say when user login user can see comment. but when user do not login user can not see comment. please help.

    ReplyDelete
  51. how to configure wamp for forgort password and email verification

    ReplyDelete
  52. Hi, why i can not get the verification code posted into my email? Can you explain it to me please?

    ReplyDelete
  53. how to solve uncaught typeERROR in php

    ReplyDelete
  54. i have got everything alright, but can not get the verification code posted into my email, just wtf?

    ReplyDelete
  55. there is no log out form please help me

    ReplyDelete
    Replies
    1. Please download code files instead of copying codes

      Delete
  56. Hi, i think i do not have SENDMAIL.INI FILE in my xampp folder... can not find it. I use macOS. Can you help me with this problem? :D Thnx so much

    ReplyDelete
    Replies
    1. It is...Please search in your folder or google it to find

      Delete
  57. Hello, I have uploaded this script to hostinger. after registration, email is failed to send and no options for smtp details. could you configure that?

    ReplyDelete
    Replies
    1. I'll solve this and update the codes as soon as possible

      Delete
  58. Hi, SUPER TY. All work fine. Can you help me with this?, Im trying put this function for encrypt the password.

    function l2j_encrypt($password){
    return base64_encode(pack("H*", sha1(utf8_encode($password))));

    I encrypt the password in (signup-user.php / new-password.php). But, I can't use the password with this encrypt here (login-user.php). TY again <3, im wait for your answer.

    ReplyDelete
    Replies
    1. You have to verify or compare user password with SHA because your DB passwords are encrypted and when user try to login, his/her password is in plain text so you've to compare it with SHA. I recommended do not use SHA. It can decrypt easily. Use password_hash.

      Delete
  59. in user data control it cam error.

    ReplyDelete

Post a Comment

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

Previous Post Next Post
CodingNepal

Don't forget to Subscribe to our YouTube Channel.

Subscribe To CodingNepal