Have you ever wondered what’s behind these sign-ups forms. Where your data goes to after filling it up. Now I’m going to tell you the secrets behind those forms, how they are being processed and used to help remember your login details.
Let’s start the first step
Create your database.
Using your phpmyadmin tool. Create your database where you can store user data. Let our database name be charming_desk.
After that, we’ll create a table named “user-login”. The same table we used in our log-in form tutorial. Now we add the following fields. “Id”, “email”, “fullname”, “password”, with their corresponding data-types now let’s begin creating our form.
Creating a sign-up form.
Now that our database has been set, we’ll move over to our sign up.php page to create the form. You can create your own sign-up.php file and continue from there. First of all, let’s enable the use of sessions in that page.
Now we can connect our sign-up page to our database with our mysqli_connect() function.
Now that we have connected our sign-up page to the database, we can now begin building our form.
Our form should contain an email, full name and a password field. And should be done as follows.
<input type="email" name="email" placeholder="write email"><br><br>
<input type="password" name="password" placeholder="type password here"><br>
<input type="password" name="cpassword" placeholder="confirm password"><br>
<input type="text" name="fullname" placeholder="e.g John Doe"><hr>
<button type="submit" name="submit">submit form</button>
If you notice we created two password fields. This will come in handy in ensuring that the user can easily remember his password or doesn’t make a mistake in the original password.
Processing the form results.
Now the most important part of this tutorial is to process the sign up form and store these data in our database. This can be a little tricky but we can handle it. We’ll start with selecting all the values with our php code.
//Now we can confirm if the two password fields have the same value.
echo "passwords are not the same";
//Insert the form values to the database.
$insert=mysqli_query($conn,"INSERT INTO user_login(email,fullname,password)VALUES('$email','$fullname','$password')");
//Redirect to restricted page(index.php)
Hashing and verifying passwords.
In order to protect the passwords from being exploited, you can use the password_hash () function to encrypt it then password verify to decrypt it.
//where password_bcrypt is the encryption method.
Now in our login.php page, we verify the password by selecting it then using the password verify method.
If you need to add a file upload button on your form, maybe to take images or PDF files, you can see How to upload images on your website using a form.
We hope this post really helped you in solving your problems. We wish you good luck in your projects and will want to see it live on the internet one day.
Feel free to follow our social media channels for more updates. Also remember to leave a comment for us, we’ll appreciate that.
You can contact us via email