Download this Blogger Template by Clicking Here!

Ad 468 X 60

Thursday 21 March 2013

Widgets

Php Tutorial - $ POST Method

$_POST Php Tutorial :

We have previously given the introduction of SuperGlobal Arrays In php. $_POST method is one of them. SO here in this post we are going to learn Post Method in depth and briefly.


Php Post Method Tutorial
Php Post Method Tutorial

What is POST Method and How To Works ?


When we add and use POST method while making a form on a page and post that form, then all the data of the form goes into that area. We can also access that area easily while we are on another page. Let’s discuss on tags of form, so that it will be more clear to you guys. If you do not know about tags, then check PHP Tags Tutorial.

Tag of form look like this

<form method=”post” action=”page.php”>

We have put two attributes in form tag.One is method and the second is action.
  • Method tells us about the method/process we are using to send data of form. It will be either post or get.
  • Second attribute is action, in which we describe the page to which we are sending the form data.
For example page.php in above example is action. Here we will give the complete path of the page. Since both these files are in same folder therefore there is no need to give the full path. But If you want to give the full path, then you can give it.  Here we are sending the form data to the page itself which contains the form.


Example :

Lets take an example.

First make a new folder in C:/xamp/htdocs and rename that new folder to form. Now open any php editor and open a new file in it. Type the code given below in the new file and save it as myform.php in c:/xamp/htdocs/form.
(myform.php)

<HTML>
<HEAD><TITLE>My First Form</TITLE></HEAD>
<BODY>
<FORM method=”post” action=”dataform.php”>
Please type your name :
<INPUT type=”text” name=”txtName”/>
<INPUT type=”submit” value=”Say Hello”/>
</FORM>
</BODY>
</HTML>



Now save these changes and now again open a new file in php editor. Paste the below code in it and save this file as dataform.php

(dataform.php)

<HTML>
<HEAD><TITLE>Form Data</TITLE></HEAD>
<BODY>
<?php
/* Now we will get the form data by using $_POST array */
$Name = $_POST[‘txtName’];
Print “Hello”.$Name;
?>
</BODY>
</HTML>

Now save this file and open web browser.Type this address and press enter
http://localhost/form/myform.php. But before typing this address, make sure that you have properly installed and configured Xampp and php tools.Now you will see a form in the browser page. Enter your name in textbox and click Say Hello Button. The Browser will you show you a message output Hello with the name you entered in the textbox.

For example if you entered Asim Nawaz in the text Box then the output message will be

Hello Asim Nawaz

How does this Program Works ?


We have made a form in myform.php file and given the name of form dataform.php in action attribute . It means that we are handling the data of form on dataform.php by using POST method. We have made a textbox in this form and given the attribute of txtName in Name attribute. You can give any name to a field of form. But the main thing is that you have to use that same attribute name while getting data from that field. We have also made a Say Hello button which will submit our form in dataform.php.

In the same way we have open the php tag in dataform.php. After that we have declared a variable named $Name and by using post area we have assigned value to it from txtName area

$Name = $_POST [‘txtName’];

We have already studied that when we post a form then all data of form fields automatically goes into $_POST Area, and then we can get that data in our related page. You can see here that to get the value of txtName field , which we have made is myform.php, we have used $_POST area to get its value.

Print “Hello”.$Name;

Now when anyone will enter his/her name in the textbox and then press submit button, then the form will be submitted to dataform.php. And there we will get the value of textbox with the help of $_POST method and then concatenate it with Hello and then print it.


Php Tutorial In Urdu :



Php Tutorial In Urdu
Php Post Method Tutorial In Urdu

Php Post Method Tutorial In Urdu
Php Post Method Tutorial In Urdu

Php Tutorial In Urdu
Php Post Method Tutorial In Urdu


SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
Author: Mohammad
Mohammad is the founder of STC Network which offers Web Services and Online Business Solutions to clients around the globe. Read More →

1 comment: