<?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; PHP</title>
	<atom:link href="http://www.webcodez.net/tag/php/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>Webcodez at Squidoo</title>
		<link>http://www.webcodez.net/php-mysql/webcodez-at-squidoo/</link>
		<comments>http://www.webcodez.net/php-mysql/webcodez-at-squidoo/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 11:26:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Javascript & AJAX]]></category>
		<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Squidoo]]></category>
		<category><![CDATA[Webcodez]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=765</guid>
		<description><![CDATA[After being very busy for a while, I started writing more PHP tutorials again. However this time I chosen Squidoo to be the place to post them. Squidoo makes it so much fun to write tutorials and it even makes it possible to earn quite some money as well ( on long term ). Therefore [...]]]></description>
			<content:encoded><![CDATA[<p>After being very busy for a while, I started writing more PHP tutorials again. However this time I chosen Squidoo to be the place to post them. Squidoo makes it so much fun to write tutorials and it even makes it possible to earn quite some money as well ( on long term ). Therefore I thought I&#8217;d post the links to the webcodez tutorials on squidoo here.</p>
<p><a href="http://www.squidoo.com/lensmasters/webcodez"><strong>Webcodez at Squidoo</strong></a></p>
<ul>
<li><a title="View This Lens" href="http://www.squidoo.com/html-basics-tutorial">HTML Basics Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-poll-system-tutorial">PHP &amp; MySQL Poll System Tu&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-basics-tutorial">PHP basics tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/css-basics-tutorial">CSS Basics Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-mysql-visitors-counter-tutorial">PHP &amp; MySQL Visitors Count&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/how-to-install-php-mysql-scripts">How to install PHP &amp; MySQL&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-mysql-login-system-tutorial">PHP &amp; MySQL Login System T&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-post-and-get-variables-tutorial">PHP POST and GET Variables Tut&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/mysql-basics-tutorial">MySQL Basics Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-banner-rotator-tutorial">PHP Banner Rotator Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-email-validation-tutorial">PHP Email Validation Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-functions-and-classes">PHP Functions And Classes</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-random-password-generation-tutorial">PHP Random Password Generation&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-smilies-system-tutorial">PHP Smilies System Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-sessions-and-cookies">PHP Sessions and Cookies Tutor&#8230;</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-arrays-tutorial">PHP Arrays Tutorial</a></li>
<li><a title="View This Lens" href="http://www.squidoo.com/php-including-files-and-securing-included-files-tutorial">PHP Including Files And Securi&#8230;</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/webcodez-at-squidoo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Regular Expressions</title>
		<link>http://www.webcodez.net/php-mysql/php-regular-expressions/</link>
		<comments>http://www.webcodez.net/php-mysql/php-regular-expressions/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 19:21:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[preg_match_all]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=750</guid>
		<description><![CDATA[Regular expressions can be used for matching or replacing certain patters inside a string. A simple example would be to check whether a certain word is inside a certain string and maybe on a certain position ( begin / end of string ). However also more complicated patterns can be made ( for example to [...]]]></description>
			<content:encoded><![CDATA[<p>Regular expressions can be used for matching or replacing certain patters inside a string. A simple example would be to check whether a certain word is inside a certain string and maybe on a certain position ( begin / end of string ). However also more complicated patterns can be made ( for example to verify whether a string is an URL address ).To do this, regular expressions can be used. Functions that make use of regular expressions in PHP are: <strong>preg_replace, preg_match and preg_match_all</strong>. These are the functions that will be used inside examples with regular expressions.</p>
<p>To match a regular expression pattern with a string, we may use the <strong>preg_match</strong> or <strong>preg_match_all</strong> function. The difference between these two functions is that preg_match stops searching for a match after one has occurred while preg_match_all continues to search for all matches. The preg_match function therefore is moreover used to check whether a pattern occurs inside a string, while the preg_match_all function is used to actually retrieve all matches with the pattern inside the string. So how do we set up a pattern? Therefore multiple symbols can be used. Here’s a table of the most common ones:</p>
<p>
<table id="wp-table-reloaded-id-1-no-1" class="wp-table-reloaded wp-table-reloaded-id-1">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Symbol</th><th class="column-2">Meaning</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">^</td><td class="column-2">The word after this symbol should be at the beginning of the string to match.</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">$</td><td class="column-2">The word before this symbol should be at the end of the string to match.</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">*</td><td class="column-2">The expression before this symbol may occur any amount of times in the string to<br />
match.</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">?</td><td class="column-2">The expression before this symbol may or may not occur once.</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">+</td><td class="column-2">The expression before this symbol should at least occur once.</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">{x}</td><td class="column-2">The expression before this symbol should occur x amount of times.</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">{x1,x1}</td><td class="column-2">The expression before this symbol should occur atleast x1 amount of times,<br />
max x2 amount of times.</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">.</td><td class="column-2">Any character.</td>
	</tr>
	<tr class="row-10 even">
		<td class="column-1">|</td><td class="column-2">Either the expression before or after this symbol should match.</td>
	</tr>
</tbody>
</table>
 
<table id="wp-table-reloaded-id-2-no-1" class="wp-table-reloaded wp-table-reloaded-id-2">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Expression</th><th class="column-2">Meaning</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">bar$</td><td class="column-2">The string to match should contain the word ‘bar’ at the end of the string.</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">^foo(.*)bar$</td><td class="column-2">The string to match should contain the word ‘foo’ at the beginning of the<br />
string AND the word ‘bar’ at the end of the string.</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">^[A-Za-z]*[0-9]*$</td><td class="column-2">The string to match should start with only letters and end with only numbers.</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">.*	</td><td class="column-2">Any amount of any characters.</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">[A-Za-z]</td><td class="column-2">Any letter ( basicly: all the characters between the brackets are allowed).</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">[A-Za-z]*</td><td class="column-2">Any amount of letters ( but also: only letters ).</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">[A-Z]|[a-z]</td><td class="column-2">Either a capital or a non-capital letter.</td>
	</tr>
	<tr class="row-9 odd">
		<td class="column-1">^foo</td><td class="column-2">The string to match should contain the word ‘foo’ at the beginning of the<br />
string.</td>
	</tr>
</tbody>
</table>
<br />
<strong>preg_match example</strong></p>
<pre name="code" class="php">

&lt;?php
//preg_match([pattern], [string], [match], [flag], [offset])

$pattern = “/^[A-Za-z0-9_]*@[A-Za-z0-9_]*\.com$/”;
$str1       = “match_example@provider.com”;
$str2       = “no_match_example@provider.nl”;
$str3       = “no-match@[test.com”;
$str4      = “example_match123@456web.com”;

if(preg_match($pattern, $str1)) {
echo “$str1 matches.”;
}else{
echo “$str1 does not match.”;
}

if(preg_match($pattern, $str2)) {
echo “$str2 matches.”;
}else{
echo “$str2 does not match.”;
}

if(preg_match($pattern, $str3)) {
echo “$str3 matches.”;
}else{
echo “$str3 does not match.”;
}

if(preg_match($pattern, $str4)) {
echo “$str4 matches.”;
}else{
echo “$str4 does not match.”;
}
?>
</pre>
<p><strong>preg_match_all example</strong></p>
<pre name="code" class="php">
&lt;?php
//preg_match_all([pattern], [string], [matches], [flag], [offset])
$pattern = “match[0-9]”;
$str         = “this is match1 and this is match2”;
if(preg_match_all($pattern, $str, $matches)) {
print_r($matches); //prints the array containing all matches found
}
?>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Classes</title>
		<link>http://www.webcodez.net/php-mysql/php-classes/</link>
		<comments>http://www.webcodez.net/php-mysql/php-classes/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 19:04:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=700</guid>
		<description><![CDATA[Object Oriented Programming ( OOP ) is programming with use of classes and objects. A class consists of constants, variables and methods ( functions to alter the class’s properties ). An object can be created from a class and can be altered by calling the class’s functions. Why would I use classes &#38; objects? You [...]]]></description>
			<content:encoded><![CDATA[<p><strong>O</strong>bject <strong>O</strong>riented <strong>P</strong>rogramming ( <strong>OOP</strong> ) is programming with use of classes and objects. A class consists of constants, variables and methods ( functions to alter the class’s properties ). An object can be created from a class and can be altered by calling the class’s functions.</p>
<h3>Why would I use classes &amp; objects?</h3>
<p>You may be asking yourself: why would I use OOP? That question has one simple answer: for writing your codes fast, efficient and keeping them clear.</p>
<h3>Creating a class</h3>
<p>As mentioned before, a class consists of constants, variables and methods. There’s one default method which ‘creates the object’. It is automaticly executed when an object of the class is created. In other words: it can be used to ‘initialize’ the object ( its default properties e.g. ). This method is called the construction ( __construct ) method.</p>
<pre name="code" class="php">class ClassName {
	public function __construct( ... arguments ...  ) {

	}
}</pre>
<p>What you may have noticed is that there’s the keyword ‘<strong>public</strong>’ before the function. This indicates that the function may be used/called from anywhere ( also from outside the class ). There are 3 types of keywords that indicate how a function may be accessed:</p>
<ul>
<li><strong>Public</strong> May be accessed from anywhere: inside the class, outside the class or from a<br />
parent  class</li>
<li><strong>Protected</strong> May be accessed from inside the class OR from a parent class.</li>
<li><strong>Private</strong> May be accessed ONLY from inside the class.</li>
</ul>
<p>Alright, knowing that, let’s go back to the construction method. The construction method may or may not need certain information to create the object and its properties. These need to be given as arguments to the class ( or: to the construction method of the class ).</p>
<p><strong>For example:</strong> for creating a <em>Product</em> object, we may need the id, name and price of the product.</p>
<pre name="code" class="php">class Product {
private static $id, $name, $price;
	public function __construct( $product_id, $product_name, $product_price ) {

	}
}</pre>
<p>The construction method now asks for the id, name and price of the product upon creating an object of the class (a <em>Product</em> object).</p>
<h3>Using &amp;amp; Creating class variables and methods</h3>
<p>To access variables and methods of the current class we use:<br />
<strong>$this-&gt;variable_name </strong>or <strong>$this-&gt;function_name(… arguments …). </strong>In the example of the product class, we can now set the class variables equal to the ones given as arguments to the construction method:</p>
<pre name="code" class="php">class Product {
private static $id, $name, $price;
	public function __construct( $product_id, $product_name, $product_price ) {
		$this-&gt;id = $product_id;
		$this-&gt;name = $product_name;
		$this-&gt;price = $product_price;
	}
}</pre>
<p>Now we can create any other functions for the class ourselves, just the same way as the construction method was formed. For example a function to ‘buy’ the product could be created:</p>
<pre name="code" class="php">class Product {
private static $id, $name, $price;
	public function __construct( $product_id, $product_name, $product_price ) {
		$this-&gt;id = $product_id;
		$this-&gt;name = $product_name;
		$this-&gt;price = $product_price;
	}

	public function buy() {
		echo “Successfully bought the product ‘”.$this-&gt;name.”’ for $”.$this-&gt;price.”!”;
	}

}</pre>
<h3>How to create an object of a class?</h3>
<p>So far we know how to create a class, but not yet how to create an actual object of the class. It’s however not so hard to do. An object of a class is created using the keyword new followed by the name of the class and brackets which may contain arguments that are required for the class ( by the construction method of the class ). An object is usually created inside of a variable:</p>
<pre name="code" class="php">$myObject = new ClassName( … arguments … );</pre>
<p>We’ll continue with the Product class we’ve been creating. The construction method requires 3 variables to be given values to: product_id, product_name and product_price. These need to be given values to when we want to create an object ( product ) of the class. We do this by giving them as arguments.</p>
<pre name="code" class="php">
$product = new Product( 1, “Example Product”, 9.95 );
</pre>
<p>This will create an object of the class and set the variable id equal to 1, name equal to “Example Product” and price equal to 9.95. We’ve created a ‘product’! Now we may use any of the public variables and functions of the class. For example the buy function we made.</p>
<pre name="code" class="php">$product = new Product( 1, “Example Product”, 9.95 );
$product-&gt;buy();</pre>
<p>This will output:</p>
<blockquote><p>Successfully bought the product ‘Example Product’ for 9.95!</p></blockquote>
<p>Note: the script of the class we created needs to be included in the script that creates the object of the class and needs to be put BEFORE it, so that the class is recognized when it’s created. Usually the code of a class definition is put in a separate file ( e.g. ClassName.class.php ) and then included into the file that uses the class. For example, assuming we put our class code inside the file Product.class.php:</p>
<pre name="code" class="php">
&lt;?php
include(“Product.class.php”);
$product = new Product( 1, “Example Product”, 9.95 );
$product->buy();
?>
</pre>
<h3>Extending classes</h3>
<p>Classes can also be <strong>extended</strong>. When this happens, we create a new class based on an earlier created class. The new (parent) class may use any methods and variables of the earlier created class ( the ‘main’ class ).</p>
<pre name="code" class="php">class MainClass {

}

class ParentClass extends MainClass {

}</pre>
<p><strong>For example:</strong></p>
<pre name="code" class="php">&lt;?php
class Product {
protected $id, $name, $price; //protected: can be accessed from parent class too
	public function __construct() { }

	public function buy() {
		echo “Successfully bought the product ‘”.$this->name.”’ for $”.$this->price.”!”;
	}
}

class Game extends Product {
protected $rank;
	public function __construct($game_id, $game_name, $game_price, $game_rank) {
		//may use any variables from the parent class (‘Product’)
		$this->id = $game_id;
		$this->name = $game_name;
		$this->price = $game_price;
		//may also create and use its own, new variables
		$this->rank = $game_rank;
	}
}

$test_game = new Game(1, “Test Game”, 19.95, 3);
//when creating an object of the Game class, the methods of the ‘main’ class may be used
$test_game->buy();
?></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>PHP GET Variables</title>
		<link>http://www.webcodez.net/php-mysql/php-get-variables/</link>
		<comments>http://www.webcodez.net/php-mysql/php-get-variables/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 11:57:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=686</guid>
		<description><![CDATA[A GET Variable is a special kind of variable that is created through the URL. They can be created by passing parameters via the URL. Take for example the following URL: http://mywebsite.com/somefile.php?var1=value1&#38;var2=value2&#38;var3=value3 When accessing the URL as shown above, there will be created a total of three GET variables: var1, var2 and var3 with the [...]]]></description>
			<content:encoded><![CDATA[<p>A GET Variable is a special kind of variable that is created through the URL. They can be created by passing parameters via the URL. Take for example the following URL:</p>
<p><a href="#">http://mywebsite.com/somefile.php?var1=value1&amp;var2=value2&amp;var3=value3</a></p>
<p>When accessing the URL as shown above, there will be created a total of three GET variables: var1, var2 and var3 with the values value1, value2 and value3. As you can see,  to add GET variables to the URL you need to put a question mark (?) after the filename. Then you can define any GET variables, separated by the AND mark (&amp;).</p>
<p>All GET variables will be created inside an array <strong>$_GET</strong>. Accessing a file somefile.php through the above example URL, would create the following GET variables in code:</p>
<p><strong>somefile.php</strong>(?var1=value1&amp;var2=value2&amp;var3=value3)</p>
<pre name="code" class="php">
$_GET[‘var1’] = “value1”;
$_GET[‘var2’] = “value2”;
$_GET[‘var3’] = “value3”;
</pre>
<p>To print all GET variables, the <strong>print_r</strong> function may be used. This may make it even more clear to see what’s happening.</p>
<pre name="code" class="php">
print_r($_GET); //prints the $_GET array on the screen
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-get-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Cookies</title>
		<link>http://www.webcodez.net/php-mysql/php-cookies/</link>
		<comments>http://www.webcodez.net/php-mysql/php-cookies/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 07:08:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[set_cookie]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=675</guid>
		<description><![CDATA[Cookies are just like sessions used for storing data that needs to be remembered and accessed from different files. However, unlike sessions, cookies are saved on the user’s browser ( client-sided ). They can be stored in there for any period unlike sessions ( which are saved for a constant ‘session period’ ). However, they [...]]]></description>
			<content:encoded><![CDATA[<p>Cookies are just like sessions used for storing data that needs to be remembered and accessed from different files. However, unlike sessions, cookies are saved on the user’s browser ( client-sided ). They can be stored in there for any period unlike sessions ( which are saved for a constant ‘session period’ ). However, they are dependent of the user’s browser and browser settings. If the user chooses to turn off cookies or if the browser simply does not allow cookies, they will not work. But none the less cookies can be quite useful and are used a lot. This is especially because they can save data for ‘unlimited’ time. Just like sessions, each cookie is a sub-variable of an array: <strong>$_COOKIES</strong>. To create a cookie variable, you simply create a sub-variable of this array. However, this time a function is needed to do so: the function <strong>set_cookie</strong>.</p>
<p><strong>full function usage</strong></p>
<pre name="code" class="php">

set_cookie( name, value, expire, path, domain, secure, httponly );
</pre>
<p><strong>basic function usage</strong></p>
<pre name="code" class="php">

set_cookie( name, value, expire);
</pre>
<p>The arguments of the function are quite a lot, however you usually only need the name, value and expiration data to be set. In fact, only the name must be given for the function to work. The other arguments are optional.</p>
<p>You can as well access any of your cookie variables on any page of your website. They do not need to be ‘activated’ or something, like for sessions, as they’re dependent of the browser. Al though, unlike sessions, cookies need to be created at the very TOP of the page.</p>
<p><strong>Example1.php</strong></p>
<pre name="code" class="php">

&lt;?php
set_cookie( “username”, “Admin”);

// now the cookie can be used anywhere in any file 

// ... rest of your webpage ...

?&gt;
</pre>
<p><strong>Example2.php</strong></p>
<pre name="code" class="php">

&lt;?php
if(isset($_COOKIES[‘username’]) &amp;&amp; !empty($_COOKIES[‘username’])) {

	echo “Welcome back, “.$_COOKIES[‘username’];

}else{

 	echo “You are not logged in.”;

}
?&gt;
</pre>
<p>You cannot use the set_cookie function after any graphical content ( HTML output ). However you can of course USE your cookies anywhere in your scripts, though they need to be created at the top of a script. For the rest, it can be used just the same way as sessions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Sessions</title>
		<link>http://www.webcodez.net/php-mysql/php-sessions-2/</link>
		<comments>http://www.webcodez.net/php-mysql/php-sessions-2/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 12:58:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SESSIONS]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=668</guid>
		<description><![CDATA[Sessions are special kind of variables which are used to store data into that needs to be ‘remembered’ and needs to be accessed from different files. For example: you need to store the username of the logged in user on your website. Once the username is stored into a variable, you do not want the [...]]]></description>
			<content:encoded><![CDATA[<p>Sessions are special kind of variables which are used to store data into that needs to be ‘remembered’ and needs to be accessed from different files. For example: you need to store the username of the logged in user on your website. Once the username is stored into a variable, you do not want the username to be lost when the user reloads the page or goes to another page of your website. Therefore, you can use special variables: sessions. All sessions belong to one array of sessions ( they are sub-variables of the array ): <strong>$_SESSION</strong>. To create a session variable, you simply create a sub-variable of this array. E.g.:</p>
<pre name="code" class="php">
$_SESSION[‘username’] = “Admin”;
</pre>
<p>You can access any of your session variables on any page of your website. However, there’s one requirement that has to be fulfilled: you need to activate sessions before you can use them. This can be done by calling the function <strong>session_start</strong>. This must be done before outputting anything graphical ( e.g. HTML / Text ). For example:</p>
<pre name="code" class="php">
&lt;?php
session_start();

$_SESSION[‘username’] = “Admin”;

//… here goes the rest of your webpage …

echo “Hi there, “.$_SESSION[‘username’].”!”;

?&gt;
</pre>
<p>Calling the function at the beginning of the file is always good.</p>
<h3>Example of usage:</h3>
<p><strong>create_session.php</strong></p>
<pre name="code" class="php">
&lt;?php
session_start();

$_SESSION[‘username’] = “Admin”;

?&gt;
</pre>
<p><strong>Note</strong>: You have to run this file to make it create the session.</p>
<p><strong>use_session.php</strong></p>
<pre name="code" class="php">

&lt;?php
session_start();

if(isset($_SESSION[‘username’]) &amp;&amp; !empty($_SESSION[‘username’])) {

	$username = $_SESSION[‘username’];

}else{

	$username = “guest”;

}

if($username == “Admin”)) {

	echo “Welcome back, Admin!”;

}else{

	echo “You’re not allowed to be here, “.$username.”!”;

}

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-sessions-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Arrays</title>
		<link>http://www.webcodez.net/php-mysql/php-arrays/</link>
		<comments>http://www.webcodez.net/php-mysql/php-arrays/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 16:57:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=653</guid>
		<description><![CDATA[An array is a special kind of ‘variable’. It consists of a group of sub-variables. Each sub-variable has, like any variable, a name ( which is called the key for a sub-variable of an array ) and a value. There is two ways to define an array. Manner 1 $my_array = array( “sub_var_1” =&#62; “value_1”, [...]]]></description>
			<content:encoded><![CDATA[<p>An array is a special kind of ‘variable’. It consists of a group of sub-variables. Each sub-variable has, like any variable, a name ( which is called the key for a sub-variable of an array ) and a value. There is two ways to define an array.</p>
<p><strong>Manner 1</strong></p>
<pre name="code" class="php">
$my_array = array(
                   “sub_var_1” =&gt; “value_1”,
                   “sub_var_2” =&gt; “value_2”,
                   “sub_var_3” =&gt; “value_3”
                 );
</pre>
<p><strong>Manner 2</strong></p>
<pre name="code" class="php">
$my_array[‘sub_var_1’] = “value_1”;
$my_array[‘sub_var_2’] = “value_2”;
$my_array[‘sub_var_3’] = “value_3”;
</pre>
<p>However, as you may already have noticed, the first manner is more like a first declaration of the array. The second manner can be used anywhere to alter the array dynamicly or add new sub-variables to it. These sub-variables work just the same way as normal variables ( a name = key, and a value ) and can be used the same way. However this time the ‘prefix’ is different as it’s not just a ‘stand-alone’ variable, but it belongs to an array of sub-variables. A sub-variable of an array is called this way:</p>
<pre name="code" class="php">
$array_name[‘sub_variable_name’]
</pre>
<p>You can as well have multiple dimensional arrays. For example:</p>
<pre name="code" class="php">
$products = array(
                  1 =&gt; array(
                             “name” =&gt; “product one”,
                             “price” =&gt; “9.95”
                             ),
                  2 =&gt; array(
                             “name” =&gt; “another product”,
                             “price” =&gt; “14.95”
                             )
		);
</pre>
<p>Now we have 2 sub-variables of the array ( each representing a product&#8217;s ID ) which as well have their own array of 2 sub-variables ( for the name and price ). They could as well be created in this manner:</p>
<pre name="code" class="php">
$products[1] = array(“name” =&gt; “product one”, “price” =&gt; “9.95”);
$products[2] = array(“name” =&gt; “another product”, “price” =&gt; “14.95”)
</pre>
<p>Or even:</p>
<pre name="code" class="php">
$products[1][‘name’] = “product one”
$products[1][‘price’] = “9.95”;
$products[2][‘name’] = “another product”;
$products[2][‘price’] = “14.95”;
</pre>
<p>Which is as well the way how you can use the variables when calling them ( by <strong>$array['sub-variable-name']</strong>, or a sub-variable of a sub-variable: <strong>$array['sub-variable-name1']['sub-variable-name2'] </strong>).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Functions</title>
		<link>http://www.webcodez.net/php-mysql/php-functions/</link>
		<comments>http://www.webcodez.net/php-mysql/php-functions/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 16:56:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[return values]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=640</guid>
		<description><![CDATA[Functions are used for processes that need to be executed various times. They make it easier, faster and more efficient to get a certain process done. To create your own function, the following structure is used: function funcName ( ... arguments ... ) { ... function process code ... } You can give the function [...]]]></description>
			<content:encoded><![CDATA[<p>Functions are used for processes that need to be executed various times. They make it easier, faster and more efficient to get a certain process done. To create your own function, the following structure is used:</p>
<pre name="code" class="php">
function funcName ( ... arguments ... ) {
	... function process code ...
}
</pre>
<p>You can give the function any name you like as long as there’s not already an existing PHP function with the same name. The arguments of the function are variables where the function needs values for ( data that’s required for your function to run ). For example: a function that retrieves all data of a user would require the user’s ID to be given as argument to the function. Upon calling the function, these arguments should be given values to. A function is called by its name followed by values for the variables that need to be given as arguments to the specific function, between brackets.</p>
<pre name="code" class="php">
funcName( … arguments … );
</pre>
<p>The function’s return can be of any type ( boolean, String, integer, anything ). However, do notice that returning a value is different from echoing a value. When a value is returned, it can be catched by a variable. When a value is echoed, it automaticly is displayed on the webpage. For example, a function that returns a value can be compared:</p>
<pre name="code" class="php">
$num = 9;
if(sqrt($num) == 3) {
	echo “The number is 9.”;
}
</pre>
<p>The function sqrt is a premade function that returns the integer square root of the number given as argument to the function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP While &#8211; Do While Loop</title>
		<link>http://www.webcodez.net/php-mysql/php-while-do-while-loop/</link>
		<comments>http://www.webcodez.net/php-mysql/php-while-do-while-loop/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 20:19:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP & MySql]]></category>
		<category><![CDATA[References]]></category>
		<category><![CDATA[do while loop]]></category>
		<category><![CDATA[loops]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[while loop]]></category>

		<guid isPermaLink="false">http://www.webcodez.net/?p=632</guid>
		<description><![CDATA[The While Loop is used to repeat executing a certain code as long as a given condition is (still) true. while( … condition … ) { … execute code … } The code between accolades is only executed when the condition between brackets is true ( just like the If Loop) however after it executed [...]]]></description>
			<content:encoded><![CDATA[<p>The While Loop is used to repeat executing a certain code as long as a given condition is (still) true.</p>
<pre name="code" class="php">
while( … condition … ) {
	… execute code …
}
</pre>
<p>The code between accolades is only executed when the condition between brackets is true ( just like the If Loop) however after it executed the code, it will go back to check the condition again; if it’s still true, it will execute the code again, etc.. This will be repeated until the condition between brackets is no longer true. Only then, it will stop executing the code and continue with the rest of your script ( below the while loop ). Therefore, you should watch out for endless while loops ( which keep repeating themselves for an infinitive time ), for ex.:</p>
<pre name="code" class="php">
$num = 1;
while($num == 1) {
	echo “Num equals 1.”;
}
</pre>
<p>As num is always equal to 1, this code will be executed forever. When that happens, the rest of your script is no longer executed and the browser will be stuck in executing the while loop script which will cause the browser to crash ( mostly ). A valid example of the use of a while loop could be for ex.:</p>
<pre name="code" class="php">
$num = 1;
while($num &lt;= 10) {
	echo “&lt;p&gt;”.$num.”&lt;/p&gt;”;
	$num++;
}
</pre>
<p>Which shows the value of $num as long as it’s not greater than 10 and then increases it by 1. In other words: it counts to 10.</p>
<p>Now, another form of the while loop is the do while loop. The difference with the while loop is that the code of the do while loop is atleast executed ONCE ( no matter if the condition is true or not ). For example:</p>
<pre name="code" class="php">
$num = 1;
do {
	echo “&lt;p&gt;”.$num.”&lt;/p&gt;”;
	$num++;
}while($num &lt;= 0);
</pre>
<p>Will result in displaying the number 1. However when we’d use the while loop instead, it would result in displaying nothing. The code would not be executed because the variable $num equals 1, which is greater than 0. The condition is false so the code won’t be executed ( not once ) in a while loop. However in a do while loop it executes it at least once but also after that it will check the condition and no longer execute the code when this condition is false.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webcodez.net/php-mysql/php-while-do-while-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

