<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Webcodez - The database of web programming tutorials &#187; POST</title>
	<atom:link href="http://www.webcodez.net/tag/post/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webcodez.net</link>
	<description>Archive of tutorials on php,mysql,Javascript,html,css and other coding languages as well as code-snippets.</description>
	<lastBuildDate>Sun, 14 Aug 2011 14:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>PHP POST Variables</title>
		<link>http://www.webcodez.net/php-mysql/php-post-variables/</link>
		<comments>http://www.webcodez.net/php-mysql/php-post-variables/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 12:43:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=691</guid>
		<description><![CDATA[A POST Variable is a special kind of variable that is used for handling form data. POST variables are created when a (POST type) form is submitted. They will contain all values of the form fields. Although a form can send its data through the POST method or the GET method. When using the POST [...]]]></description>
			<content:encoded><![CDATA[<p>A POST Variable is a special kind of variable that is used for handling form data. POST variables are created when a (POST type) form is submitted. They will contain all values of the form fields. Although a form can send its data through the POST method or the GET method. When using the POST method, the values of the form fields are stored inside these POST variables. There will be created an array <strong>$_POST</strong> containing all data. Each form field has its own sub-variable to this array (<strong>$_POST[‘<em>form_field_name</em>’]</strong>). Take for example this form:</p>
<pre name="code" class="html">
&lt;form method=”POST” action=”&lt;?=$_SERVER[‘PHP_SELF’];?&gt;”&gt;
&lt;input type=’text’ name=’username’&gt;
&lt;input type=’password’ name=’password’&gt;
&lt;input type=’submit’ name=’submitBut’ value=’Login!’&gt;
&lt;/form&gt;
</pre>
<p>The above form has 3 fields. Two of them are text fields which can be given values to by the user. The other ‘field’ is a submit button ( which will automaticly be given the value ‘Login!’ in this example ). The method of the form is set to ‘POST’, which means: once the user presses the submit button, all form data is stored into the $_POST array and sent to the target page ( as set in the action parameter of the form tag ). In this example form the values of 3 fields will be stored inside the $_POST array like this:</p>
<pre name="code" class="php">
$_POST[‘username’] = “ ... “;
$_POST[‘password’] = “ ... “;
$_POST[‘submit’]      = “Login!”;
</pre>
<p>Where <em>…</em> would be replaced by the user filled in values.</p>
<p><strong>How to check whether a form was submitted<br />
</strong>We know that once a form is submitted the $_POST array is created containing all form data. Therefore we can just check whether the $_POST array is set to define whether the form was submitted.</p>
<pre name="code" class="php">
&lt;?php
if(isset($_POST) AND !empty($_POST)) { //if the $_POST array is set and not empty
	//... form was submitted ...
}else{
	//... form isn’t submitted yet ...
}
?&gt;
</pre>
<p>Note: If multiple forms can be submitted at one page, you could identify the submitted form by checking<br />
for example the POST variable for the submit button of that form.</pre>
<p><strong>Example of usage</strong></p>
<pre name="code" class="php">
&lt;?php
if(isset($_POST) AND !empty($_POST)) { //if the $_POST array is set and not empty
	//... form was submitted ...
	// -&gt; show filled in form values
	echo “&lt;p&gt;&lt;b&gt;Username:&lt;/b&gt; “.$_POST[‘username’].” &lt;/p&gt;”;
	echo “&lt;p&gt;&lt;b&gt;Password:&lt;/b&gt; “.$_POST[‘password’].” &lt;/p&gt;”;
}else{
	//... form isn’t submitted yet ...
	// -&gt; show form
?&gt;
	&lt;form method=”POST” action=”&lt;?=$_SERVER[‘PHP_SELF’];?&gt;”&gt;
	&lt;input type=’text’ name=’username’&gt;
	&lt;input type=’tetx’ name=’password’&gt;
	&lt;input type=’submit’ name=’submitBut’ value=’Login!’&gt;
	&lt;/form&gt;
&lt;?php
}
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-post-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

