Create PHP Registration Form Using POST Method – Simplilearn
Times of India (The leading News Media Company) confirms that one of the most top-paying coding jobs is in the field of PHP.
One of the basic skills a PHP developer should have is the ability to create a form. This tutorial will walk you through the step-by-step process of creating a PHP registration form, where users can complete the process of registration with the help of other details like username, email, and password.
If you want to see how to log in after creating a registration form, you better refer to the PHP login form article, for better clarity.
Before you begin with these topics, it is vital to know the prerequisites.


Suppose you want to learn the step-by-step process to download and install this software, please click here.
Now, you will begin this tutorial by creating a responsive form using CSS.

For the registration form, write the code mentioned below in a new PHP file. Regiser.php:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
font-family: Calibri, Helvetica, sans-serif;
background-color: grey;
}
.container {
padding: 50px;
background-color: #f7dc6f ;
}
input[type=text], textarea {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
div {
padding: 10px 0;
}
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
.registerbtn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}
</style>
</head>
Note: .css file helps developers design the website in the desired way.
After this, create a file in the Microsoft studio and save it as style.css. Write the code depicted below in the style.css file and modify your file as required:

Next comes the most important part, wherein you have to add the required details of a PHP form.
<body>
<?php
$fullname = $email = $gender = $comment = $age = "";
if ($_
“L{SERVER["REQUEST_METHOD"] == "POST") {
$fullname = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$comment = test_input($_POST["comment"]);
$gender = test_input($_POST["gender"]);
$age = test_input($_POST["age"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

Here you will create a form for the registration page with the method as POST.
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="container">
<center> <h1>Registeration Form</h1> </center>
<hr>
<label> <b>Fullname</b> </label>
<input type="text" name="name" placeholder= "Fullname" size="50" required />
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="age"><b>Age</b></label>
<input type="text" placeholder="Enter Age" name="age" required>
<div>
<label>
<b>Gender : </b>
</label><br>
<input type="radio" value="Male" name="gender" checked > Male
<input type="radio" value="Female" name="gender"> Female
<input type="radio" value="Other" name="gender"> Other
</div>
Here, in the gender field, you used the type as radio to create a selection display.
Now write the PHP code to display the details on the page itself.
<label>
<b>Comment : </b>
<textarea name="comment" cols="50" rows="2" placeholder="Current Address" value="address" required>
</textarea>
<button type="submit" class="registerbtn">Register</button>
</form>
<?php
echo "<h2>Your Input:</h2>";
echo $fullname;
echo "<br>";
echo $email;
echo "<br>";
echo $age;
echo "<br>";
echo $gender;
echo "<br>";
echo $comment;
echo "<br>";
?>
</body>
</html>
Output 1:
Once you enter the data, you will get the following output:

Output2:
Congratulations, you have successfully created a PHP registration form.

This brings us to the conclusion of the PHP Registration Form tutorial. Here, you learned how to create a PHP Registration form, to create a CSS sheet for the registration form, and how to save user details with the POST method on Microsoft Visual Studio.
Are you planning to take up a PHP certification? If yes, Simplilearn's PHP course would be the right choice for you. The PHP certification of Simplilearn includes all the basic and advanced concepts, thus helping you easily learn PHP.
Do you have any questions for us? Please feel free to put them in the comments section of this tutorial; our experts will get back to you at the earliest. To learn more, watch the following video:
Simplilearn is one of the world’s leading providers of online training for Digital Marketing, Cloud Computing, Project Management, Data Science, IT, Software Development, and many other emerging technologies.
Post Graduate Program in Full Stack Web Development
Full Stack Web Developer - MEAN Stack
*Lifetime access to high-quality, self-paced e-learning content.
The Ultimate Guide to Creating Chatbots
Session in PHP : Creating, Working With, and Destroying a Session
A Complete Guide to Create a PHP Login Form
The Building Blocks of API Development
Array in PHP
An In-Depth Explanation of PHP Form Validation
© 2009 -2023- Simplilearn Solutions
Follow us!
Company
Work with us
Discover
For Businesses
Learn On the Go!
Trending Post Graduate Programs
Trending Bootcamp Programs
Trending Master Programs
Trending Courses
Trending Categories
Trending Resources
source