Forms and PHP

Welcome to bbn11!. In these posts, we cover form and php. Forms are the most basic things in system development pars. Without our form tag, we can not do anything about registration, logging in to the system, and other things that users feed to the system from the system like search.

Form Tags

The form tag is an HTML element that is used to provide user input type and submit value from the user or client to the servers. Form tags provide input fields and submit values to the server. Form tags have two main methods

  1. POST
  2. GET

POST Methods

Post is a form tags method that is used to path data from the client side to the server side. In the Post method, the value of data is passed through hidden and not displayed on the URL of the browsers.

Post method syntax

<form action="form.php" method="POST">
<input type="text" placehoder="Enter Name">
<input type="submit" value="Save">

The above code is about how to use posts in the form of HTML tags, HTML Input fields, and submit html attributes.

GET Methods

The get method is similar to the post method, but in the get method we have summited data visible to the URL unline when using the post method data is hidden and not displayed on URLs. This method is used when we write the query of search value from a database or from the internet.

Syntax of GET Methods

<form action="form.php" method="GET">
<input type="text" placehoder="Enter Name">
<input type="submit" value="Save">

the above code shows how to use the GET method on HTML and PHP tags

Examples of HTML and PHP Forms

Let create a form that is used to summit user information from clients and send it to the server and server processes the summited data and displays it to the registered client by using the get and post methods.

To create a form follow the following steps.

Step 1: Create a PHP file and name it registeration.php

Step 2: Create HTML elements that show the form to the client’s interface

Step 3: Your form must have an input type where the client Enter the data.

Step 4: The form must contain one button that is used to submit your data and have submit attributes

Step 5: The summited data must be displayed to clients.

Let’s start coding now

create register.php

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registration Fomr</title>
<h2>Personal Information Registration</h2>
<form action="#" method="POST">
<label>First Name</label><br>
<input type="text" name="fname" placeholder="First Name"> <br>
<label>Middle Name</label><br>
<input type="text" name="mname" placeholder="Middle Name"> <br>
<label>Last Name</label><br>
<input type="text" name="lname" placeholder="Last Name"> <br>
<input type="email" name="email" placeholder="Email"> <br>
<textarea rows="8" cols="35"> Enter Yor Bio.....</textarea> <br>
<input type="submit" name="submit" value="Register">


echo "<br> ============== <br>";
echo "Your First Name: ". $fname .'<br>';
echo "Your Middle Name: ". $mname .'<br>';
echo "Your Last Name: ". $lname .'<br>';
echo "Your Email Address: ". $email .'<br>';


The Output of the above code is as follows

Session And Cookies On PHP


HTTP is a stateless protocol. Stateless means, the browser does not register client information that accesses the system, browser does not care about who accesses it.

In stateless protocol servers do not care about the client information. The server does not store client information.


Cookies are a small piece of data that works on web browsers. Typically cookies storage maximum of 4K. Web browsers can use cookies to identify users from others. Cookies can configured for a specific time.

Cookies have expiration dates based on our configurations

Cookies life is active when the web browser is open. When a web browser is closed cookies data is also deleted from web browsers.

Generally, the life of one cookie is the life of an open browser.

Cookies extension of HTTP protocols.

Cookies have two HTTP header protocols

  1. Set_cookies response header
  2. Cookies request headers

Create A Cookies

Use setcookie() function to create cookies.

Syntax of creating cookies

setcookie(string cookiest_name, string cookiest_value, int expire, string cookiest_path, string domain, int secure);


//Setting Cookies

What is Session ?

Session is used to store data for a short period of time. The session’s maximum lifetime is 24 Minutes. After 24 minutes sessions totally destroyed. The session can be configured as what we need.

How to Start Session in PHP

To strat session in PHP use the following

At the top session must start and be used in the system when we want.

Syntax of session


Author: bbnadmin

1 thought on “Forms and PHP

Leave a Reply

Your email address will not be published. Required fields are marked *