All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Registration Form In PHP With Database

Last Updated : Mar 11, 2024

Registration Form In PHP With Database

In this article we will show you the solution of registration form in PHP with database, complete registration form made from form html file, registering process php file and database connection file.

As usual, users need to register their name to access particular service provider platform.

While customers entering their details those data are need to store on database to verify when they next time trying with registered information.

If information matches with customer input they will allow or they are not allowed. And then to connect database and retrieving file each other connection execution file defined.

Step By Step Guide On Registration Form In PHP With Database :-

First you need to create html file with input fields required for registration.

Within form remember to specify method and action attribute to achieve the result.

In each input field name attributes and respective values plays vital role to retrieve and access user entered inputs.

Create php file with mysqli_connect() method and appropriate values. This single line make you able to store or access database with different queries.

To store registering people’s information like name, password, email create another php file.

Here, you need to check whether user pressed submit button or not.

If pressed check every input was not null and allowing execute insert query to store users data to database of table. Lastly, error or success message throw at client side to notify user.

Regis.html

<html>
<head>
<title>REGISTRATION FORM</title>
<body>
<form name="registration" method="post" action="Registration.php">
Username:<input type="text" name="nm" value=""></br>
Email:<input type="text" name="em" value=""></br>
Password:<input type="text" name="psw" value=""></br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</head>
</html>

Registration.php

<?php
require('connection.php');
if(isset($_REQUEST['submit'])!='')
{
if($_REQUEST['nm']=='' || $_REQUEST['em']=='' || $_REQUEST['psw']=='')
{
Echo "please fill the empty field.";
}
Else
{
$sql="insert into userlevels(uname,email,pass) values('".$_REQUEST['nm']."', '".$_REQUEST['em']."', '".$_REQUEST['psw']."')";
$res=mysqli_query($con,$sql);
if($res)
{
Echo "Registration was successful";
}
Else
{
Echo "There is some problem in registration";
}
}
}?>

connection.php

<?php
$hn="localhost";
$un="root";
$pas="";
$db="dbase";
$con=mysqli_connect($hn,$un,$pas,$db);
if(! $con)
{
die('Connection Failed'.mysql_error());
}
?>
  1. A php script can be placed anywhere in the document. A php script starts with <?php and end with ?>.
  2. The default file extension for php files is “.php” and php statements end with ‘;’ semicolon. In php we need to specify ‘$’ symbol before the variable name also default rule.
  3. We created registration form through html file with fields ‘Username, Email, Password’. In form tag specify ‘method’ attribute with ‘post’ value and ‘action’ attribute with ‘Registration.php’.
  4. When user click on Submit button after entering all inputs these two attributes bring end users data to Registration.php file.
  5. There first connection.php file executed to create connection with database ‘dbase’. Using if() condition we checking Submit button whether entered by user or not through (isset($_REQUEST['submit'])!='') condition.
  6. If return yes another if() checks every input tag filled with value or null by line ‘$_REQUEST['nm']==''’. Here ‘nm’ denotes html file’s Username input tag by ‘name’ attributes value. Likewise, all input values checked that are filled or null.
  7. If not null, else block executed where insert query executed with values of end user entered data. These are stored to table ‘userlevels’ on respective columns ‘uname,email,pass’.
  8. To execute this query ‘mysqli_query()’ method was defined with parameters of query variable ‘$sql’ and database connection variable $con.
  9. Echo statement will print message as based on your execution result. Instead echo() you can prefer print() method if you want and that not going to affects your result.

Conclusion :-

In conclusion, hope now you know how to create registration form with database using php.

When you work with php we need to create and process php files at server location and then we need to start the server before execute the program.

Otherwise sometimes you will get error so ensure it if you get any error while running output.

When we execute this program on browser it will show 4 input fields you need to fill them and click on Submit button.

If program has no error you will get ‘Registration was successful’ as output or if you get ‘There is some problem in registration’ this as result you need to find and fix error.

With this help of sample code you can test all types of float variables and decimal places count.

I hope this article on registration form in PHP with database helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪