<?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>Capable SEO &#187; Code</title>
	<atom:link href="http://www.capableseo.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.capableseo.com</link>
	<description></description>
	<lastBuildDate>Mon, 12 Apr 2010 08:42:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inserts and Queries</title>
		<link>http://www.capableseo.com/inserts-and-queries.html</link>
		<comments>http://www.capableseo.com/inserts-and-queries.html#comments</comments>
		<pubDate>Mon, 28 Dec 2009 02:22:15 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=100</guid>
		<description><![CDATA[Instructions on how to create some basic queries and inserts are here. At the completion of this tutorial you will be able create a page which will let people create usernames and passwords.

First create a new .php file. You&#8217;ll need to create a basic form which posts to itself. The form needs to have 2 [...]]]></description>
			<content:encoded><![CDATA[<p>Instructions on how to create some basic queries and inserts are here. At the completion of this tutorial you will be able create a page which will let people create usernames and passwords.</p>
<ol>
<li>First create a new .php file. You&#8217;ll need to create a basic form which posts to itself. The form needs to have 2 input text fields named &#8220;username&#8221; and &#8220;password&#8221; along with a submit button. The code for this is displayed below, I recommend just copying the info below and pasting it into your php file.<textarea onclick="this.select();" cols="70" rows="6" name="textarea">&lt;br /&gt; &lt;head&gt;&lt;br /&gt; &lt;title&gt;User Create&lt;/title&gt;&lt;br /&gt; &lt;/head&gt;&lt;/p&gt; &lt;form name=&#8221;form1&#8243; method=&#8221;post&#8221; action=&#8221;"&gt; &lt;table width=&#8221;350&#8243; border=&#8221;0&#8243; cellspacing=&#8221;0&#8243; cellpadding=&#8221;0&#8243;&gt; &lt;tr&gt; &lt;td&gt; &lt;div align=&#8221;center&#8221;&gt;Username&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div align=&#8221;center&#8221;&gt;         &lt;input name=&#8221;username&#8221; type=&#8221;text&#8221; id=&#8221;username&#8221;&gt;       &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div align=&#8221;center&#8221;&gt;Password&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div align=&#8221;center&#8221;&gt;         &lt;input name=&#8221;password&#8221; type=&#8221;text&#8221; id=&#8221;password&#8221;&gt;       &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div align=&#8221;center&#8221;&gt;         &lt;input type=&#8221;submit&#8221; name=&#8221;Submit&#8221; value=&#8221;Create&#8221;&gt;       &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;p&gt;</textarea></li>
<li>Now that you have a form setup which will send information to you we get on to the php coding.</li>
<li>Inside the code at the top of the page (above everything) create a section for your PHP code <span class="style2">&lt;?php ?&gt;</span></li>
<li>Your first step will be to receive the variables sent by the form, afterall if no variables are sent theres no reason to waste loading time. So add to the script a bit with the following. Form data is contained within a global variable labled <span class="style2">$_POST</span>. You can then access the<br />
individual fields by changing the name from &#8220;username&#8221; to whatever you wish.</p>
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"></p>
<p><span style="color: #0000BB">&lt;?php<br />
$username</span><span style="color: #007700">=</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">];<br />
</span><span style="color: #0000BB">?&gt;</span></p>
<p></span><br />
</code></td>
</tr>
</tbody>
</table>
</li>
<li>Now we&#8217;ll need to test to see if there was any information in that variable. This code just performs a check, to see if what is inside the parenthesis () is true.<br />
If it is true then it will do something else (that something is contained within the <span class="style2">{ }</span> tags. In the statement <span class="style2">if ($username)</span> we are saying if something happened to <span class="style2">$username</span> do the following.</p>
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br />
</span><span style="color: #007700">if (</span><span style="color: #0000BB">$username</span><span style="color: #007700">)<br />
{</p>
<p>}</p>
<p></span><span style="color: #0000BB">?&gt;<br />
</span> </span></code></td>
</tr>
</tbody>
</table>
</li>
<li>Finally we&#8217;re on to the real query section. Here we will need to define the other variables of <span class="style2">$password</span> and <span class="style2">$uid</span> connect to the database. Check to see if any other users already have the chosen username. The insert the new username and password combination into the database. First lets connect to the database. Remember all of this code will be within the <span class="style2">{ }</span> tags from the if statement in step 5.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br />
</span><span style="color: #007700">if (</span><span style="color: #0000BB">$username</span><span style="color: #007700">)<br />
{<br />
</span><span style="color: #FF8000">/* you need to connect using the proper username and password if<br />
you installed the wamp server and didn't change any settings your<br />
username will be 'root' and your password wil be blank<br />
the below is a standard connect with password and username</p>
<p>mysql_connect("localhost", 'yourusername', 'yourpassword')</p>
<p>the below is what you can use if you still have the default wamp<br />
installation settings*/</p>
<p></span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">'root'</span><span style="color: #007700">)<br />
or<br />
die(</span><span style="color: #DD0000">"could not connect"</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">/* by adding the "or die" on to this you make the system report<br />
an error message. If theres a problem*/<br />
</span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"school"</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">//Please choose the database name you created in the last tutorial;<br />
</span><span style="color: #007700">}<br />
</span><span style="color: #0000BB">?&gt;<br />
</span> </span></code></td>
</tr>
</tbody>
</table>
</li>
<li>Ok now that you are connected to the database we should create the variables you&#8217;ll be using. First the password, this is basically a repeat of Step 4.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"></p>
<p><span style="color: #0000BB">&lt;?php<br />
$password</span><span style="color: #007700">=</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">[</span><span style="color: #DD0000">'password'</span><span style="color: #007700">];<br />
</span><span style="color: #0000BB">?&gt;<br />
</span></p>
<p></span><br />
</code></td>
</tr>
</tbody>
</table>
</li>
<li>Now lets create the final variable the Unique ID. This will allow you keep track of data in an anonymouse way. In this step there are several functions including a random number creator, and a while loop.The random number creator will come first, this allows us to create a new ID for this user&#8217;s account.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php<br />
</span><span style="color: #FF8000">/* the statement below will set $uid as a random number<br />
between 1 and 999,999. This gives us a 6 digit unique<br />
identification number.*/<br />
</span><span style="color: #0000BB">$uid</span><span style="color: #007700">=</span><span style="color: #0000BB">rand</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,</span><span style="color: #0000BB">999999</span><span style="color: #007700">);<br />
</span><span style="color: #0000BB">?&gt;<br />
</span> </span></code></td>
</tr>
</tbody>
</table>
<p>Now we&#8217;ll run a check to see if there another ID equal to the newly generated one above. This is the first query.</p>
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"><br />
<span style="color: #0000BB">&lt;?php</p>
<p></span><span style="color: #FF8000">/*query the table, this returns information<br />
regarding a row with the random id above.*/<br />
</span><span style="color: #0000BB">$query</span><span style="color: #007700">=</span><span style="color: #DD0000">"SELECT * FROM users WHERE uid='$uid';"</span><span style="color: #007700">;<br />
</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die(</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br />
</span><span style="color: #FF8000">//place the results of the query into a variable<br />
</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">/*create a dummy variable with the value of username from the table.<br />
This will be blank if there aren't any users with the same id number.*/<br />
</span><span style="color: #0000BB">$dummy</span><span style="color: #007700">=</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">];<br />
</span><span style="color: #0000BB">?&gt;<br />
</span> </span></code></td>
</tr>
</tbody>
</table>
<p>The following which is a loop which will means it will happen again and again as long as the requirements are met.</p>
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"></p>
<p><span style="color: #0000BB">&lt;?php</span></p>
<p></span><span style="color: #FF8000">//while the $dummy != (is not equal) to "" (nothing) do what is inside the {}<br />
</span><span style="color: #007700">while (</span><span style="color: #0000BB">$dummy</span><span style="color: #007700">!=</span><span style="color: #DD0000">""</span><span style="color: #007700">)<br />
{<br />
</span><span style="color: #FF8000">//first make dummy equal to nothing<br />
</span><span style="color: #0000BB">$dummy</span><span style="color: #007700">=</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br />
</span><span style="color: #FF8000">//set the uid to a new random number<br />
</span><span style="color: #0000BB">$uid</span><span style="color: #007700">=</span><span style="color: #0000BB">rand</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,</span><span style="color: #0000BB">999999</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">//query the database<br />
</span><span style="color: #0000BB">$query</span><span style="color: #007700">=</span><span style="color: #DD0000">"SELECT * FROM users WHERE uid='$uid';"</span><span style="color: #007700">;<br />
</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die(</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br />
</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">/*set dummy as equal to the username, if the uid was<br />
unique then the username will now be equal to ""*/<br />
</span><span style="color: #0000BB">$dummy</span><span style="color: #007700">=</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'username'</span><span style="color: #007700">];<br />
}<br />
</span><span style="color: #FF8000">//finish the loop with a }<br />
</span><span style="color: #0000BB">?&gt;<br />
</span></code></td>
</tr>
</tbody>
</table>
</li>
<li>Now we&#8217;ll check to make sure the username isn&#8217;t already in the database and then either show an error message or insert the new user/password into the database.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000"></p>
<p><span style="color: #0000BB">&lt;?php</span></p>
<p></span><span style="color: #FF8000">/*query the database, similar to the first part of step 5,<br />
however instead of uid, we're looking at username*/<br />
</span><span style="color: #0000BB">$query</span><span style="color: #007700">=</span><span style="color: #DD0000">"SELECT * FROM users WHERE username='$username';"</span><span style="color: #007700">;<br />
</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die(</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br />
</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />
</span><span style="color: #FF8000">/*set dummy as equal to the uid, if the username was<br />
unique then the uid will now be equal to ""*/<br />
</span><span style="color: #0000BB">$dummy</span><span style="color: #007700">=</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'uid'</span><span style="color: #007700">];</p>
<p></span><span style="color: #FF8000">//if the username alraedy has information in it then display an error mesage<br />
</span><span style="color: #007700">if (</span><span style="color: #0000BB">$dummy</span><span style="color: #007700">!=</span><span style="color: #DD0000">""</span><span style="color: #007700">)<br />
{<br />
echo </span><span style="color: #DD0000">"Sorry $username is already registered, please choose another username"</span><span style="color: #007700">;<br />
</span><span style="color: #FF8000">/*notice I used $ in front of username. This will make the<br />
variable appear in the error message*/<br />
</span><span style="color: #007700">}</p>
<p></span><span style="color: #FF8000">/*or else do this (so if the if statement above isn't true insert a<br />
new row into the database.*/<br />
</span><span style="color: #007700">else<br />
{<br />
</span><span style="color: #0000BB">$query</span><span style="color: #007700">=</span><span style="color: #DD0000">"INSERT INTO `users` ( `username` , `password` , `uid` )<br />
VALUES ('$username', '$password', '$uid');"</span><span style="color: #007700">;<br />
</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">) or die(</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br />
echo </span><span style="color: #DD0000">"username: $username, password: $password created sucessfully"</span><span style="color: #007700">;<br />
</span><span style="color: #FF8000">// the echo gives a success message which details the username and password.<br />
</span><span style="color: #007700">}</p>
<p></span><span style="color: #0000BB">?&gt;<br />
</span></code></td>
</tr>
</tbody>
</table>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/inserts-and-queries.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Posts and Redirects</title>
		<link>http://www.capableseo.com/php-posts-and-redirects.html</link>
		<comments>http://www.capableseo.com/php-posts-and-redirects.html#comments</comments>
		<pubDate>Fri, 07 Aug 2009 05:47:35 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=102</guid>
		<description><![CDATA[Now we&#8217;re going to add in some functionality to your php. We&#8217;ll make a form which checks a person&#8217;s age then either redirects them to a different page, or displays an error message.

First off is some html code for a form, the form will send via post method one variable for age.
&#60;form method=&#8221;post&#8221;&#62;Age &#60;input name=&#8221;age&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Now we&#8217;re going to add in some functionality to your php. We&#8217;ll make a form which checks a person&#8217;s age then either redirects them to a different page, or displays an error message.</p>
<ol>
<li>First off is some html code for a form, the form will send via post method one variable for age.<br />
<span>&lt;form method=&#8221;post&#8221;&gt;Age &lt;input name=&#8221;age&#8221; type=&#8221;text&#8221; id=&#8221;age&#8221;&gt;&lt;/form&gt;<br />
</span></li>
<li> So now you&#8217;ve got a basic form that has a field for age. Now lets put in some a php code area and get started <span>&lt;?php ?&gt;<br />
</span></li>
<li>Now we need to put a variable there to catch whatever is posted back to the document. You can assign a vairable to a post like in the example.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
</span><span style="color: #ff8000;">/*$_POST is the method for describing a posted variable, then you describe the id of<br />
the variable within the [' '] tags.*/<br />
</span><span style="color: #0000bb;">$age</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$_POST</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'age'</span><span style="color: #007700;">];<br />
echo </span><span style="color: #dd0000;">"Age: $age"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out <span>Age: </span> if you just start the page, and if you submit an age it will say <span>Age: [your age here]</span>.</li>
<li>Now lets add in a simple if statement determining if the age is below a certain point, if it is say below 13 we&#8217;ll assign a variable <span>$error</span> a sentence detailing how this site is made for those 13 or above.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$age</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$_POST</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'age'</span><span style="color: #007700;">];<br />
if (</span><span style="color: #0000bb;">$age</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">13</span><span style="color: #007700;">) {</span><span style="color: #0000bb;">$error</span><span style="color: #007700;">=</span><span style="color: #dd0000;">"Sorry this site is only for those aged 13 or above."</span><span style="color: #007700;">}<br />
</span><span style="color: #ff8000;">/* just having the variable in an if statement's ()s checks to see if the<br />
variable has been assigned anything or not. If it has it will run the statement.*/<br />
</span><span style="color: #007700;">if (</span><span style="color: #0000bb;">$error</span><span style="color: #007700;">) {echo </span><span style="color: #0000bb;">$error</span><span style="color: #007700;">;}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>Depending on what you submit to the page this will either print nothing or it will print <span>Sorry this site is only for those aged 13 or above.<br />
</span></li>
<li>Lets add in an <span>else</span> statement so that if they are able to see the site it will tell them that the site is redirecting them there now.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$age</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$_POST</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'age'</span><span style="color: #007700;">];<br />
if (</span><span style="color: #0000bb;">$age</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">13</span><span style="color: #007700;">) {</span><span style="color: #0000bb;">$error</span><span style="color: #007700;">=</span><span style="color: #dd0000;">"Sorry this site is only for those aged 13 or above."</span><span style="color: #007700;">}<br />
if (</span><span style="color: #0000bb;">$error</span><span style="color: #007700;">) {echo </span><span style="color: #0000bb;">$error</span><span style="color: #007700;">;}<br />
else { echo </span><span style="color: #dd0000;">"Your old enough to view the site, redirecting you now."</span><span style="color: #007700;">;}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This will either tell the person they&#8217;re too young or tell them they&#8217;re old enough and the site is redirecting.</li>
<li>The final part of the script is actually redirecting a person if they are of the correct age. So add in the following code to the redirect. <span>header(&#8217;Location: http://www.example.com/&#8217;);</span><br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$age</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$_POST</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'age'</span><span style="color: #007700;">];<br />
if (</span><span style="color: #0000bb;">$age</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">13</span><span style="color: #007700;">) {</span><span style="color: #0000bb;">$error</span><span style="color: #007700;">=</span><span style="color: #dd0000;">"Sorry this site is only for those aged 13 or above."</span><span style="color: #007700;">}<br />
if (</span><span style="color: #0000bb;">$error</span><span style="color: #007700;">) {echo </span><span style="color: #0000bb;">$error</span><span style="color: #007700;">;}<br />
else { echo </span><span style="color: #dd0000;">"Your old enough to view the site, redirecting you now."</span><span style="color: #007700;">;<br />
</span><span style="color: #ff8000;">//remember you would be changing example.com below to whatever url you need.<br />
</span><span style="color: #0000bb;">header</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Location: http://www.example.com/'</span><span style="color: #007700;">);}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This will either tell you that your not old enough or redirect you to http://www.example.com, This lesson is now over.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/php-posts-and-redirects.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to do PHP While Loops</title>
		<link>http://www.capableseo.com/how-to-do-php-while-loops.html</link>
		<comments>http://www.capableseo.com/how-to-do-php-while-loops.html#comments</comments>
		<pubDate>Thu, 30 Jul 2009 14:02:02 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[basics]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=104</guid>
		<description><![CDATA[Now that you know how to use if then statements lets move on to a basic loop.

Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. &#60;?php ?&#62;
Now lets add in a variable and an echo statement. Give one variable [...]]]></description>
			<content:encoded><![CDATA[<p>Now that you know how to use if then statements lets move on to a basic loop.</p>
<ol>
<li>Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. <span>&lt;?php ?&gt;</span></li>
<li>Now lets add in a variable and an echo statement. Give one variable a value of 0 then echo it.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out <span>0</span>.</p>
<p>PHP generally starts many constructs at 0, not at 1 so its generally better to start counting from 0 in programming..</li>
<li>Now lets add in a basic loop. The while statement is very similar to an if statement except a while loop will do the things as long as its conditions are met (or until timeout which is generally 3-5 minutes depending on your server settings).<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
</span><span style="color: #007700;">while (</span><span style="color: #ff8000;">/*requirements*/</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #ff8000;">//Stuff to do<br />
</span><span style="color: #007700;">}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This won&#8217;t print anything yet</li>
<li>Now lets make that actually do something. We&#8217;ll have it run 5 times, so while <span>$x</span>&lt;5 do something. Of course we have to increase <span>$x</span> inside the loop otherwise it won&#8217;t end. So the only action we have right now is adding one to <span>$x</span>, we can do this with <span>$x=$x+1;</span> or in english x is equal to x +1.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This won&#8217;t print anything yet</li>
<li>Now lets add on an echo so we can see the progress of <span>$x</span> counting up towards 5.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out &#8220;<span>12345</span>&#8220;</li>
<li>Ok now there is a better way to add one to <span>$x</span> and thats a special operation which is coded like this <span>++$x;</span></li>
<li>Now lets add some text to each echo so it looks a bit nicer. You can print a variable and letters by using an echo with quotes. so in this statement <span>echo &#8220;x: $x&#8221;;</span> the first x will simply be the letter x and the second one which is preceded by a $ will be the variable.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"x=$x"</span><span style="color: #007700;">;<br />
++</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out &#8220;<span>x: 1x: 2x: 3x: 4x: 5</span>&#8221;<br />
Now this doesn&#8217;t look much nicer (actually it looks worse!), but we&#8217;ll fix that in the next step.</li>
<li>A PHP echo will place code directly into the html of a file. So if you type html code into the echo you can use different html functions to change displays. In this way you can make things bold, manipulate css styles etc. For now we&#8217;ll just add a <span>&lt;br&gt;</span> to the end of each line this will make the numbers go to different lines.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
while (</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">5</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"x=$x&lt;br&gt;"</span><span style="color: #007700;">;<br />
++</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out:<br />
<span>x: 1<br />
x: 2<br />
x: 3<br />
x: 4<br />
x: 5</span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/how-to-do-php-while-loops.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If Then Math PHP Statements</title>
		<link>http://www.capableseo.com/if-then-math-php-statements.html</link>
		<comments>http://www.capableseo.com/if-then-math-php-statements.html#comments</comments>
		<pubDate>Wed, 15 Jul 2009 04:43:02 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=49</guid>
		<description><![CDATA[
Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. &#60;?php ?&#62;
Now lets add in some basic variables and an echo statement. Give two variables a value of 2, and a third variable a value equal to the previous to [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Lets get started by opening your favorite editor and starting a fresh source page. Start off with the basic coding which denotes a php area. <span>&lt;?php ?&gt;</span></li>
<li>Now lets add in some basic variables and an echo statement. Give two variables a value of 2, and a third variable a value equal to the previous to variables added together.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">$number</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out <span>4</span> .</li>
<li>Try changing the <span>+</span> to different mathmatical operators these are:<br />
<span>/</span> Divide<br />
<span>*</span> Multiply<br />
<span>-</span> Subtract</li>
<li>Now we&#8217;re going to add in an if then statement. Basically if statements are logical, if certain requirements are met then do something. An if then statement looks like this<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
</span><span style="color: #007700;">if (</span><span style="color: #ff8000;">/*requirements*/</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #ff8000;">//Stuff to do<br />
</span><span style="color: #007700;">}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>The if statement is one of the few that doesn&#8217;t require a <span>;</span> after it.</li>
<li>Now lets a simple statement that says, &#8216;if&#8217; <span>&#8216;$number</span> is not equal to four&#8217; &#8216;echo Thats not Four&#8217;. This code looks like this.<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;</p>
<p>if (</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">!=</span><span style="color: #0000bb;">4</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"Thats not Four"</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print out &#8220;<span>Thats not Four</span>&#8221;</p>
<p>The comparison operators in PHP are as follows:<br />
<span>!=</span> Is not equal to<br />
<span>==</span> Equal to<br />
<span>&gt;</span> Greater than<br />
<span>&lt;</span> Less than<br />
<span>&gt;=</span> Greater than or Equal to<br />
<span>&lt;=</span> Greater than or Equal to</li>
<li>Now lets say you want to check if the number is between 5 and 10. You&#8217;ll need to use two checks in the if instead of one. So you need to say &#8216;if&#8217; <span>&#8216;$number</span> is greater than or equal to 5 and less than or equal to 10&#8242; &#8216;echo number is between 5 and 10&#8242;. The code for this looks like this:<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;</p>
<p>if (</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&gt;=</span><span style="color: #0000bb;">5 </span><span style="color: #007700;">&amp;&amp; </span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&lt;=</span><span style="color: #0000bb;">10</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"number is between 5 and 10"</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This shouldn&#8217;t print anything</p>
<p>Logical Operators for PHP<br />
<span>&amp;&amp;</span> and<br />
<span>||</span> or</li>
<li>Now this is fine and all except what, happens when your number doesn&#8217;t fit the criteria? Nothing happens. So lets add on the final part of an If Then statement. So now PHP will go if <span>$number</span> is between 5-10 do this, or else do this. The code looks like this:<br />
<table border="0" cellspacing="0" cellpadding="0" width="350" bgcolor="#cccccc">
<tbody>
<tr>
<td><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$x</span><span style="color: #007700;">=</span><span style="color: #0000bb;">1</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">=</span><span style="color: #0000bb;">2</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">=</span><span style="color: #0000bb;">$x</span><span style="color: #007700;">+</span><span style="color: #0000bb;">$y</span><span style="color: #007700;">;</p>
<p>if (</span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&gt;=</span><span style="color: #0000bb;">5 </span><span style="color: #007700;">&amp;&amp; </span><span style="color: #0000bb;">$number</span><span style="color: #007700;">&lt;=</span><span style="color: #0000bb;">10</span><span style="color: #007700;">)<br />
{<br />
echo </span><span style="color: #dd0000;">"number is between 5 and 10"</span><span style="color: #007700;">;<br />
}<br />
else<br />
{<br />
echo </span><span style="color: #dd0000;">"number is less then 5 or greater than 10"</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">?&gt;<br />
</span> </span> </code></td>
</tr>
</tbody>
</table>
<p>This should print <span>number is less then 5 or greater than 10</span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/if-then-math-php-statements.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World</title>
		<link>http://www.capableseo.com/hello-world.html</link>
		<comments>http://www.capableseo.com/hello-world.html#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:39:41 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.capableseo.com/?p=26</guid>
		<description><![CDATA[A small step for PHP (Hypertext Preprocessor) everywhere is just a simple &#8220;Hello World&#8221;. So we&#8217;ll out line a few basic commands here.

Make sure you have a PHP enabled server on your computer. My preference is Wamp Server it installs a complete package with the latest PHP, MySQL tools and systems.
Use your favorite processor to [...]]]></description>
			<content:encoded><![CDATA[<p>A small step for <strong>PHP </strong>(Hypertext Preprocessor) everywhere is just a simple &#8220;Hello World&#8221;. So we&#8217;ll out line a few basic commands here.</p>
<ol>
<li>Make sure you have a PHP enabled server on your computer. My preference is <a href="http://www.wampserver.com/en/download.php">Wamp Server</a> it installs a complete package with the latest PHP, MySQL tools and systems.</li>
<li>Use your favorite processor to start a .php file. If you aren&#8217;t sure which allows you to do this, simply use notepad. If you use notepad when you save the file, choose all files from the list, then make your filename end in .php You should make sure that you save the .php file to your PHP testing server, generally on your local computer this folder will be called WWW.</li>
<li> Second you need to tell the internet browser that your starting a section that will have PHP code inside of it. so you should use the basic identifiers to incase the code. <span class="style2">
<p>&lt;?php          ?&gt;</span></p>
<p>Everything contained within the &lt;?php and ?&gt; will be considered PHP code. All functions inside will be processed before the website loads. For this reason if there is an error in the PHP code, the entire website will likely not work, and either show an error, or a blank page. For this reason its important to test all PHP pages before launching them.</li>
<li> Now we&#8217;ll move on and create a new variable. Think algebra, &#8216;<span class="style2">X=4</span>&#8216; etc. In PHP all variables have always have a $ sign. Therefore it would be &#8216;<span class="style2">$X=4</span>&#8216;. Finally you have to add one more thing to make this a complete variable declaration (actually making <span class="style2">$X</span> equal 4). You need to add a colon <span class="style2">;</span> after. This lets PHP know that your done with your command. The complete code looks like this.<br />
<table border="0" cellspacing="0" cellpadding="0" width="300" bgcolor="#cccccc">
<tbody>
<tr>
<td class="style3">&lt;?php</p>
<p>$X=4;</p>
<p>?&gt;</td>
</tr>
</tbody>
</table>
<p>So now X is equal to 4. Of course the object of this lesson is to write &#8220;Hello World&#8221; so instead of making $X equal to 4 lets make it equal to &#8220;Hello World&#8221;.</p>
<table border="0" cellspacing="0" cellpadding="0" width="300" bgcolor="#cccccc">
<tbody>
<tr>
<td class="style3">&lt;?php</p>
<p>$X=&#8221;Hello World&#8221;;</p>
<p>?&gt;</td>
</tr>
</tbody>
</table>
<p>Quite easy to change isn&#8217;t it. PHP is unique in that it defines variables based on what you put place in it. This makes it much easier then many programs since you don&#8217;t often have to worry about what types of variables are.</li>
<li>We&#8217;re nearing the finish of our short tutorial. Now you need to actually place the words &#8220;Hello World&#8221; onto the screen. This is done by using the &#8216;echo&#8217; function. The code works like this &#8216;<span class="style2">echo</span>&#8216; &#8216;<span class="style2">$variable</span>&#8216; &#8216;<span class="style2">;</span>&#8216; this allows you to place whatever is in the variable onto the screen. So lets place that into our code from above and make the program work.<br />
<table border="0" cellspacing="0" cellpadding="0" width="300" bgcolor="#cccccc">
<tbody>
<tr>
<td><span class="style3">&lt;?php</p>
<p>$X=&#8221;Hello World&#8221;;</p>
<p>echo $X;</p>
<p>?&gt; </span></td>
</tr>
</tbody>
</table>
</li>
<li>Now you need to make sure you saved this to a place on your PHP enabled server. Go to it with your favorite web browser and you should see the words &#8220;<span class="style2">Hello World</span>&#8220;. Feel free to change the words around and experiment with it.</li>
<li>Common errors:
<ul>
<li>Forgetting to place a <span class="style2">;</span> after a statement.</li>
<li>Capitalization can cause no end of problems. PHP is a case sensitive programming language, which means that you could have two variables, <span class="style2">$X</span> and <span class="style2">$x</span> and they could be two completely different things! You also need to call the functions by their correct name, for example if you said <span class="style2">Echo</span> instead of <span class="style2">echo</span> the above function wouldn&#8217;t have worked.</li>
</ul>
</li>
</ol>
<p>This is the end of the first PHP Tutorial</p>
]]></content:encoded>
			<wfw:commentRss>http://www.capableseo.com/hello-world.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
