Please note, this is a STATIC archive of website technosmarter.com from July 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
 

SignUp Form using PHP & MYSQL | Simple Registration System


SignUp form in PHP

In this tutorial, we will create a SIGNUP system. If you want to insert the data of students or employees in the MYSQL database, you can create a SignUp form. You need to have a knowledge of HTML form and PHP Script, only then you can create a registration form.

In the previous tutorial, we created a login form using PHP and MYSQL which can also be known as SignIn form. All websites have to SignUp before signIn. It is a simple SIGN UP form using PHP.

Registration form using MYSQL & PHP

When we create a dynamic website, you have to take data from the users. To take data from the users, we create a dynamic form which we can also call the registration form or signup form. To create a registration system, we create a table inside the MYSQL database. We must also know the query of MYSQL for registration.

The information is inserted into the database by using the SQL query in the PHP script.INSERT query is used to add data into the MYSQL database using PHP and HTML form.

MYSQL insert query for registration form

MYSQL queries are used to create dynamic forms. To insert the data, we should understand the INSERT query. We INSERT all data into the MYSQL table using database table name and columns name. Registration is done by the INSERT query. Let's have a look at the INSERT query.
 
 
 INSERT INTO `table_name`(`column_1`, `column_2`, `column_3`, `column_4`, `column_5`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5]);
 
 

In the above INSERT query , we define the columns name and values.

Create an MYSQL database table

To create a sign-UP system, you have to create a table in a database. There are two ways to make the table in MYSQL database.

1. Use the PHP my admin panel.

2. Create an MYSQL Database table using a query.

We create columns inside the table.Before making a registration form, we decide the fields. For all the fields, make columns.


  CREATE TABLE  `user` (

 `id` INT( 50 ) NOT NULL ,
 `name` VARCHAR( 40 ) NOT NULL ,
 `gender` VARCHAR( 30 ) NOT NULL ,
 `dob` VARCHAR( 30 ) NOT NULL ,
 `email` VARCHAR( 40 ) NOT NULL ,
 `mobile` VARCHAR( 43 ) NOT NULL ,
 `password` VARCHAR( 40 ) NOT NULL
);

Make an HTML form

In the previous tutorial, we created an HTML form for a Login system. In this tutorial, we create an HTML form for registration. The SignUp form contains the all decided fields. The user fills the information in the form and submits it. In the HTML form, we use POST and GET methods. The POST and GET method is used to form handling requests. These are REQUEST methods in PHP. Let's create a form.

<html>
<body>
<center>
<form action="" method="post"
<fieldset>
 Sign Up
Name:-


Gender :- Male Female

DOB:-

Email :-

Mobile:-

Password



</fieldset > </form> </center>

Design a SIGN UP form using CSS stylesheet

Along with PHP programming, if designing of the form is also good, then it is fun. The registration form should be attractive along with the form functionality. We use CSS stylesheet for designing a form. Let's design a SignUp form via CSS stylesheet.


  

  

Create a config file

The config file hanles the connection between PHP form and MYSQL database.

Now, create a file and save with name and extension "config.php".

<?php

$databaseHost = '127.0.0.1';//or localhost
$databaseName = 'test'; // your db_name
$databaseUsername = 'root'; // root by default for localhost 
$databasePassword = '';  // by defualt empty for localhost

$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);
 
?>

In above config file , we used mysqli_connect() function for a new connection. We passed this information as a parameter and stored it in a variable $mysqli. You can change database host, database name, database username, and database Password according to your needs.

Create a PHP script for User registration

To create a dynamic form, we have to use PHP scripts. Under PHP we only perform logical code. The following steps have to be followed to create a PHP script for the registration form.

1. First of all, include the config.php file using include() function. You can use require() function to include config.php. This a connection file to use connect the database to form.



2. Now create if condition to set the fields data on submit button. if the data inserted successfully it prints a successful statement and if the error occurred , it returns error statements. Create a condition according your code execution. 3. Use MYSQL insert query to insert data into database using SignUp form.



PHP Script code

<?php
include("config.php");
if(isset($_POST['submit']))
{
	$name = $_POST['name'];
	$gender = $_POST['ab'];
	$dob = $_POST['dob'];
	$email = $_POST['email'];
	$number = $_POST['number'];
	$password = $_POST['password'];
	$result = mysqli_query($mysqli,"insert into user values('','$name','$gender','$dob','$email','$number','$password')");
	if($result)
	{
		echo "Registration Successfully";
	}
	else{
		echo "failed:";
	}
}
?>

SIGN UP using POST method in PHP

In the previous tutorial, we have discussed the POST method in PHP . The POST handles the form data. It sends data to the server via an HTTP header. You can send unlimited data on the server. There is no limit to the POST method.
In the above registration form, we used the POST method. The POST method helps you send kind of data like - Images, audio, video, documents, word, pdf, etc. The POST method is one of the best methods for security purpose for Sign in and Signup system.

SignUp using the GET method

Along with POST method, you can also create registration system by using the GET method.The GET method sends form information to the sever by encoded. The endcoded infrmation seprated by the ? sign with page URL. You can send string data types with the GET method. There is a limit with the POST method, we discussed the limit in the GET method in PHP tutorials. There is no security with the GET method. The form values visiable in page url separated by ? (question mark) .

    
https://example.com/registration.php?user=ram&pass=ram123&submit=Submit

Create registration form PHP script using the GET method

We created a script with the POST method. Here, we create a PHP script using the GET method.

<?php
include("config.php");
if(isset($_GET['submit']))
{
	$name = $_GET['name'];
	$gender = $_GET['ab'];
	$dob = $_GET['dob'];
	$email = $_GET['email'];
	$number = $_GET['number'];
	$password = $_GET['password'];
	$result = mysqli_query($mysqli,"insert into user values('','$name','$gender','$dob','$email','$number','$password')");
	if($result)
	{
		echo "Registration Successfully";
	}
	else{
		echo "failed:";
	}
}
?>

In the above example, we changed POST to GET. Let's change in HTML form.

<html>
<body>
<center>
<form action="" method="GET"
<fieldset>
 Sign Up
Name:-


Gender :- Male Female

DOB:-

Email :-

Mobile:-

Password



</fieldset > </form> </center>

In the above HTML form, you need to change method POST to GET. Try both examples with the GET and POST methods.


Please Share

Recommended Posts:-