Showing posts with label Php Tutorials. Show all posts
Friday, 22 March 2013
Php Tutorial - $ Get Method
$_GET Method Php Tutorial :
I am sure that you have now properly understood and got the Introduction of SuperGlobal Arrays In php, as we have discussed it in our previous posts. $_GET method is one of the SuperGlobal Arrays which is very important concept in php. Here in this post we are going to learn Get Method in depth and briefly, so that you can understand it well. You can also check $_POST method tutorial.
What is $_GET Method ?
$_GET is also a superglobal array which is based on querystrings that are sent with the URL. You may have already seen many querystrings in web addresses of different sites. For example
http://www.example.com/search.php?keyword=pakistan
You can see in this example that along with URL a Querystring is also sent along with the URL. In the Querystring , there is a question mark ? after the name of the page in URL.
One URL can have more than one Querystrings. Like
http://www.example.com/search.php?keyword=pakistan&city=isb
In the above URL, we have two Querystrings. One is keyword and the second is city. Both these Querystrings are connected with & symbol. For getting the value of such a Querystring, we use $_GET method.
Let us understand it using an example
Make a new folder in c:/xampp/htdocs and rename the new folder with name as get. Now open your php text editor and open a new file in it. Put the code in it which is given below and save this file in c:/xampp/htdocs/get as link.php.
(link.php)
<HTML>
<HEAD>
<TITLE> Using Get Method </TITLE>
</HEAD>
<BODY>
<a href=”get.php?site=MyTricksLab”> Sending Querystring </a>
</BODY>
</HTML>
Save this file. Now open a new file In php editor and put the following code in it and save this file in C:/xampp/htdocs/get with name get.php
(get.php)
<HTML>
<HEAD>
<TITLE> Get Querystring Data </TITLE>
</HEAD>
<BODY>
<?php
/* Now We will get the Querystring Data by using $_GET array */
$siteName = $_GET[‘site’];Print “ Welcome To “.$.siteName ;
?>
</BODY>
</HTML>
Save this file and open it in in your web browser by typing this address
http://localhost/get/link.php and then press enter.Make sure before typing this address, that you have properly installed and configured Xampp and php tools. Now a link will come on page that we have made using href tag. When you will click on this link then this message will appear on screen
Welcome To MyTricksLab
After clicking the link, check the address bar in the browser. You will see a link just like this
http://localhost/get/get.php?site=MyTricksLab
In this URL, site is a Querystring whose value is MyTricksLab. We are getting this value from another page get.php using $_GET array. If we are using get in the method of the form then the data of fields of form will automatically become a Querystring and will become the part of URL and we can get this by using $_GET array method.
Php Tutorial Get Method In Urdu :
Read More »
Labels:
Computer Science,
Get Method,
PHP,
Php Tutorials,
Programming,
Tricks and Tutorials,
Web Development
Thursday, 21 March 2013
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 |
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 Post Method Tutorial In Urdu |
![]() |
Php Post Method Tutorial In Urdu |
![]() |
Php Post Method Tutorial In Urdu |
Read More »
Labels:
Computer Science,
PHP,
Php Tutorials,
Programming,
Tricks and Tutorials,
Web Development
Subscribe to:
Posts (Atom)