Form Handling in PHP

After that much knowledge of Theory Let’s Look at Example.If you find difficulty feel free to contact us.

Form Handling Example.

For that you must be aware of form tags and other html tags how they works. Take a look at karan.html file below :

<title>Welcome to kanulp’s Blog</title>
<form action=”gajjar.php” method=”post”>
<table border=0>

<h1 aligh=center>Information:</h1>
<td><input type=”text” required=”required” name=”fname”
placeholder=”Karan Gajjar”></td>

<td><input type=”text” name=”email”

<td><input type=”number” name=”age” size=3 required=”required”
<td><select name=”lan”>

<option value=”php” name=”language”>PHP</option>
<option value=”C” name=”language”>C</option>
<option value=”python” name=”language”>Python</option>
<option value=”java” name=”language”>Java</option>

<td><input type=”radio” value=”Male” required=”required”
<td><input type=”radio” value=”Female” required=”required”

<td colspan=2><input type=”submit” value=”Submit”></td>


This should be like:


Now Let’s work with these Inputs to do so PHP helps us.

save another file as mention in form action attribute like mine is gajjar.php.

<head><title>Your information</title>
<h3>Hi <?php echo $_POST[“fname”]?>,</h3>


$a = $_POST[‘age’];
$lang = $_POST[‘lan’];
$sex = $_POST[‘sex’];

if($lang==”C” && $a>16)
echo “Omg “.$_POST[“fname”].”! You Don’t know “.$lang.” at
the age of “.$a.”?”;
else if($lang==”php”){

echo “So Mr. “.$_POST[“fname”].”. You are good to go with “.
$lang.” and This blog will help you Stay tuned!”;}


echo “So Miss. “.$_POST[“fname”].”. You are good to go with
“.$lang.” and This blog will help you!”;}


echo “Wow! You found at the age of



How this works is with the help of $_POST[] . This helps us to collect form data.Same as you can use $_GET[] if you have set your method=”get” in html file.

Basically developers do not use get method as per can see your data which you’ve entered in html file in URL when you click on submit.

REMEMBER: This is done through server only where PHP interpreter is set and executes our scripts.


Author: kanu_lp

Teck Geek guy... Bands Obsessed.

1 thought on “Form Handling in PHP”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s