<?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>Wowebmaster.com &#187; sguler</title>
	<atom:link href="http://www.wowebmaster.com/author/sguler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wowebmaster.com</link>
	<description>World of Webmaster: Sharing Experiences</description>
	<lastBuildDate>Sun, 23 Jan 2011 23:40:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Centering Web Page</title>
		<link>http://www.wowebmaster.com/css/css-centering-web-page/</link>
		<comments>http://www.wowebmaster.com/css/css-centering-web-page/#comments</comments>
		<pubDate>Sat, 02 May 2009 20:40:02 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=93</guid>
		<description><![CDATA[A quick trick to center your web site horizontally by using CSS]]></description>
			<content:encoded><![CDATA[<p>If you are new to CSS, you may be having diffucult to center web pages horizontally. I remember I was trying to center the page by defining extra divs with align:center attributes. That is not necessary though. Just adding a margin attribute which is set to &#8220;auto&#8221; for left and right would do the trich to center your pages. See the following css code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p93code1'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p931"><td class="code" id="p93code1"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* CSS Document */</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/*For IE6 Shenanigans*/</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">907px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* Centering Page */</span></pre></td></tr></table></div>

<p>You see the margin attribute ? By setting it to auto, the margins to the left and right will be automatic, which means your page will be centered. Of course, you have to specify a width for your div, otherwise the browser will not be able to calculate the margins to the left and right. The following shows the HTML code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p93code2'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p932"><td class="code" id="p93code2"><pre class="html" style="font-family:monospace;">&lt;!--CTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt--&gt;
&lt;div id=&quot;content&quot;&gt;
&nbsp;
&lt;!-- ALL THE CONTENT GOES HERE --&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>That&#8217;s it. Enjoy.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fcss%2Fcss-centering-web-page%2F&amp;linkname=CSS%20Centering%20Web%20Page"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/css/css-centering-web-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sIFR Lite: Faster &amp; Smaller sIFR</title>
		<link>http://www.wowebmaster.com/javascript/sifr-lite-faster-smaller-sifr/</link>
		<comments>http://www.wowebmaster.com/javascript/sifr-lite-faster-smaller-sifr/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:49:16 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[sifr]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=29</guid>
		<description><![CDATA[sIFR Lite, a smaller amd faster alternative for the original sIFR]]></description>
			<content:encoded><![CDATA[<p><strong>Typography Solution</strong></p>
<blockquote><p>&#8220;95% of the information on the web is written language. It is only logical to say that a web designer should get good training in the main discipline of shaping written information, in other words: Typography.&#8221;</p></blockquote>
<p>A good web designer knows the importance of typography in creating web sites. As <a href="http://informationarchitects.jp/the-web-is-all-about-typography-period/">this post</a> mentions, typography is in fact the most important part of designing stylish web pages. However, it is in fact a little problematic to get all the fonts work in internet browser, the sIFR is the solution.</p>
<p><strong>What is sIFR ?</strong><br />
sIFR, Scalable Inman Flash Replacement, simply detects texts and replaces them with a flash movie, which can illustrate the any font you embed in. Speaking of how it works, it is a simple javascript file doing the replacement, it has also the flash movie, which you can edit in Adobe Flash so that you can add the font you want to use in your web page.</p>
<p><strong>sIFR is slow</strong><br />
Every good thing at internet, has disadvantages. Despite the fact sIFR produces beautiful typography, size of the required file is not that small. The required javascript file is about 22kB (uncompressed), required css file is about 3kB and the flash movie is usually between 10kB and 20kB, depending on the font used and embedded characters.</p>
<p><strong>Faster &amp; Smaller Version: sIFR Lite</strong><br />
In order to reduce the size, <a href="http://www.allcrunchy.com/Web_Stuff/sIFR_lite/">someone</a> rewrote the sifr&#8217;s javascript file, to form a lite version and to provide a faster way of replacing texts. He named it sIFR Lite. The sIFR Lite&#8217;s javascript is just 3.7K (uncompressed), reduced from 22kB, so it actually saves bandwidth for you and time for your visitors. From developer&#8217;s site:</p>
<p><strong>sIFR Lite comparing to original sIFR</strong><br />
1. It is smaller. This library is 3.7k uncompressed. The original sIFR is 22k, no joke!<br />
2. It auto-detects the text color of the elements. (The original sIFR makes you enter it manually!)<br />
3. It is completely object-oriented. (No more static methods floating all over the place.)<br />
4. It no longer uses CSS selectors. Elements are targeted by tag name and class. (A slight loss in ease of use, but faster, lighter, and more maintainable.)<br />
5. It isn&#8217;t named after myself, or anyone else. haha.</p>
<p>I highly recommend you to use the sIFR Lite instead of the original sIFR. Despite the fact sIFR lite has no support for CSS selectors (resulting some bugs for heading tags in internet explorer; but there is a workaround), it is way small and fast comparing to the original sIFR. Meaning, you can enjoy the typography beauty on your site faster because of the reduced size of the sIFR javascript.</p>
<p><strong>sIFR Lite Usage</strong><br />
I will explain it step by step.</p>
<p>First download all the zip file from the original <a href="http://novemberborn.net/sifr/2.0.7">sIFR creator&#8217;s website</a> .<br />
Contents of zip file:</p>
<ul>
<li>css/sIFR-print.css</li>
<li>css/sIFR-screen.css</li>
<li>js/sifr.js</li>
<li>js/sifr-config.js</li>
<li>flash/sifr.fla</li>
</ul>
<p>Now, open sifr.fla and edit the font of the text  (choose a font to use) and publish the flash movie.</p>
<p>Download the sIFR lite <a href="http://www.wowebmaster.com/demo/sifr.lite.js">here</a> ( the problem mentioned in the comments below, is fixed, thanks to <a href="#comment-74">Patrick</a> ) and replace it with <em>js/sifr.js</em>. Also remove the <em>js/sifr-config.js</em>. Don&#8217;t forget to edit the font path in <em>sifr.lite.js</em>.</p>
<p>Defining the text replacements are so simple, following javascript replaces h1.mySpecialClass, h2.mySpecialClass and h3.mySpecialClass texts with the flash movie, <em>tradegothic.swf</em>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p29code3'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p293"><td class="code" id="p29code3"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> gothic <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Font<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tradegothic.swf'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
&nbsp;
tags<span style="color: #339933;">:</span><span style="color: #3366CC;">'h1,h2,h3'</span><span style="color: #339933;">,</span>
&nbsp;
classFilter<span style="color: #339933;">:</span><span style="color: #3366CC;">'mySpecialClass'</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
gothic.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Put the above code inside your body tags. Also reference the js/sifr.js and all css files inside your head tags. That&#8217;s it. You should now have had the sifr working correctly in your web page.</p>
<p>You can also use it without targeting any class. If you&#8217;d like to target all heading tags and want all of them replaced, you can use the following javascript.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p29code4'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p294"><td class="code" id="p29code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> gothic <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Font<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tradegothic.swf'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
&nbsp;
tags<span style="color: #339933;">:</span><span style="color: #3366CC;">'h1,h2,h3'</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
gothic.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p><a href="http://www.wowebmaster.com/demo/sifr-lite.html" target="_blank"><br />
</a></p>
<h4><a href="http://www.wowebmaster.com/demo/sifr-lite.html" target="_blank">sIFR Lite Demo</a></h4>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fjavascript%2Fsifr-lite-faster-smaller-sifr%2F&amp;linkname=sIFR%20Lite%3A%20Faster%20%26%23038%3B%20Smaller%20sIFR"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/javascript/sifr-lite-faster-smaller-sifr/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Firebug in IE: Debugging JavaScript in Internet Explorer</title>
		<link>http://www.wowebmaster.com/javascript/firebug-in-ie-test-javascript-in-internet-explorer/</link>
		<comments>http://www.wowebmaster.com/javascript/firebug-in-ie-test-javascript-in-internet-explorer/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 00:11:16 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[IE7]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=28</guid>
		<description><![CDATA[Javascript bug hunt in Internet Explorer: Firebug Lite]]></description>
			<content:encoded><![CDATA[<p>I have been using the firebug extension of Mozilla Firefox for a while to debug my javascript applications. It is so handy, useful, tricky and excellent. You can check what your script is doing on the html, see all the reflections of your code and as a result, it helps you find the errors on your javascript code. So if you are new to this, please read the details on <a href="http://getfirebug.com">firebug site</a> and add the firebug extension to your Mozilla Firefox.</p>
<p>For some IE bugs and differences, you may not see the IE reflection of your javascript code rendered in Mozilla, so you better see the test results using the internet explorer. I&#8217;ve googled if there is any kind of program doing that and the firebug was the answer again. According to Google&#8217;s results, there is the firebug lite, which you can include inside your website&#8217;s head tags and have the same firebug extension in Mozilla, in Internet Explorer.</p>
<p><strong>Firebug Lite Usage</strong></p>
<p>Just add the following code inside your page&#8217;s head tags and launch it using Internet Explorer. Firebug console must be visible at the bottom of the page.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code5'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p285"><td class="code" id="p28code5"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fjavascript%2Ffirebug-in-ie-test-javascript-in-internet-explorer%2F&amp;linkname=Firebug%20in%20IE%3A%20Debugging%20JavaScript%20in%20Internet%20Explorer"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/javascript/firebug-in-ie-test-javascript-in-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Testing Your Web Design in IE6 &amp; IE7</title>
		<link>http://www.wowebmaster.com/css/testing-your-design-in-ie6-ie7/</link>
		<comments>http://www.wowebmaster.com/css/testing-your-design-in-ie6-ie7/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 08:45:30 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=26</guid>
		<description><![CDATA[Work-around: Install IE6 and IE7 at Same Computer, Side by Side!]]></description>
			<content:encoded><![CDATA[<p>If you are a designer, then you know how it is complicated to code sites with cross-browser support. IE6 hacks,  Safari support, CSS resets and so on&#8230; You keep trying to balance your website across all browsers. Half of pain is because of installing and testing all of the browsers at the same time. However you also know that you can&#8217;t install internet explorer 6 and internet explorer 7 at the same time to your computer.</p>
<p><strong>Installing IE6 and IE7 Side by Side</strong></p>
<p>With a few googles, i found out  that you can actually install IE6 and IE7 in one computer. A few hacks to windows registry database, and a few file additions and deletions. Don&#8217;t be afraid, because someone has simplified it. Tredosoft is offering a software that supports Multiple IEs in one computer . Just download and run the file at <a style="color:#ff0000" title="Multiple IE Installation" href="http://tredosoft.com/Multiple_IE" target="_blank">this page</a> and start testing your web designs in multiple internet explorer versions ( IE5, IE6 and IE7). Enjoy.</p>
<p><a href="http://tredosoft.com/Multiple_IE" target="_blank"><img class="alignnone size-full wp-image-27" title="setup1" src="http://www.wowebmaster.com/wp-content/uploads/2008/12/setup1.png" border="0" alt="" width="406" height="317" /></a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fcss%2Ftesting-your-design-in-ie6-ie7%2F&amp;linkname=Testing%20Your%20Web%20Design%20in%20IE6%20%26%23038%3B%20IE7"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/css/testing-your-design-in-ie6-ie7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE6 Negative Margin Problem</title>
		<link>http://www.wowebmaster.com/css/ie6-negative-margin-problem/</link>
		<comments>http://www.wowebmaster.com/css/ie6-negative-margin-problem/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 07:46:06 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Css]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=25</guid>
		<description><![CDATA[Work Around: Negative Margins in IE6]]></description>
			<content:encoded><![CDATA[<p>Designers should have faced with the problem of creating cross-browser designs. We have to serve to all of the visitors. Some may use Mozilla, some Internet Explorer 6 or IE7.</p>
<p>Usually, problem is related to IE6&#8217;s rendering engine.  One of the most common problem with IE6 is that it doesn&#8217;t render the negative margins as IE7 and Mozilla does. Negative margins is rendered hidden out of the layer in IE6.  Setting overflow to visible does not work and you go crazy.</p>
<p>The work around, making the negative margins visible, is so simple, it is even one of the simplest work arounds of the problems in IE6. Just add <em>position:relative</em> to your element with negative margins. This is it. Enjoy.</p>
<blockquote><p>position:relative</p></blockquote>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fcss%2Fie6-negative-margin-problem%2F&amp;linkname=IE6%20Negative%20Margin%20Problem"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/css/ie6-negative-margin-problem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Auto Refreshing Iframes</title>
		<link>http://www.wowebmaster.com/javascript/auto-refreshing-iframes/</link>
		<comments>http://www.wowebmaster.com/javascript/auto-refreshing-iframes/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 07:46:42 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[refresh]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/?p=21</guid>
		<description><![CDATA[How to auto refresh iframes with javascript]]></description>
			<content:encoded><![CDATA[<p>Quoted from Wikipedia, &#8220;IFrame (from Inline Frame) is an HTML element which makes it possible to embed an HTML document inside another HTML document&#8221;.</p>
<p>If you are using iframes to serve frequently updated feeds on your site, such as a score board, news feed, then you should provide your visitors an iframe updating automaticaly while the page stays same. This is accomplished by a javascript function. You can easily set a time interval to refresh a specific iframe on your page by this way. As a result, your users don&#8217;t have to refresh the whole page every time to update the feed flow.</p>
<p>Put the following function inside head tags on your page.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code6'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p216"><td class="code" id="p21code6"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Also put an onload attribute for the body tag, similar to the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p217"><td class="code" id="p21code7"><pre class="html" style="font-family:monospace;">&nbsp;</pre></td></tr></table></div>

<p>Finally, don&#8217;t forget to name your iframe as it is called in javascript function (&#8221;iframename&#8221; in this example).</p>
<p>An example using this function is a <a href="http://www.goalvideos.tv/live-scores/">football live scores</a> page.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fjavascript%2Fauto-refreshing-iframes%2F&amp;linkname=Auto%20Refreshing%20Iframes"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/javascript/auto-refreshing-iframes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learn PHP by Examples</title>
		<link>http://www.wowebmaster.com/php/learn-php-by-examples/</link>
		<comments>http://www.wowebmaster.com/php/learn-php-by-examples/#comments</comments>
		<pubDate>Thu, 15 May 2008 10:07:38 +0000</pubDate>
		<dc:creator>sguler</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.wowebmaster.com/blog/?p=6</guid>
		<description><![CDATA[A PHP teaching series with lots of examples]]></description>
			<content:encoded><![CDATA[<p>Since you are here to learn Php by examples, I&#8217;m assuming you have intermediate knowledge of HTML at least. So I will give you examples of easy php scripts that will teach you how php works. First of all, what is PHP ?</p>
<div id="wphp"><strong>What is PHP ?</strong></div>
<p>PHP is a server-side HTML-embedded scripting language, as PHP.net (PHP Homepage) stated. Meaning, PHP is generally embedded into HTML. When someone visits your PHP page, server compiles it and translates to plain HTML, before sending to visitor. Visitor only gets the HTML coded page which is formed by PHP script. That&#8217;s why they call PHP as a Server-Side Scripting Language.</p>
<div><img class="size-full wp-image-7" title="php-server-side" src="http://www.wowebmaster.com/wp-content/uploads/2008/05/php-server-side.gif" alt="Php Server Side Scripting" width="290" height="135" /></div>
<p>Now, you know that you won&#8217;t be able to view your php files using your internet browsers without putting them on a server. You need a server to put your php files. You have two choices, you can form your PC into a server, meaning you can install apache web server software (working as a php-compiler) on your PC or you can buy a php included web hosting server.</p>
<p>* Installing Apache (PHP,MySql) Server on your PC ?<br />
Easy. Just install Xampp (XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl) on your PC, and your PC will be your own web server. <a href="http://www.apachefriends.org/en/xampp-windows.html" target="_blank">Xampp Installation Link</a></p>
<p>* Web Hosting ?<br />
I suggest you try free web hosting services. Choose your free php hosting service from <a href="http://www.0php.com/free_PHP_hosting.php">this page</a>. Sign-up for free using a subdomain.</p>
<p>Now, we can start if you have a server to test your php files. But before starting, I suggest you install <a href="http://www.adobe.com/products/dreamweaver/">Adobe&#8217;s Dreamweaver</a> which has an easy php-html editor. It is useful for everyone, it will help you much.</p>
<p>Here is the contents of this Php Tuturial:</p>
<blockquote>
<h4>Contents:</h4>
<ul>
<li><a href="#wphp">What is PHP?</a></li>
<li><a href="#hworld">Hello World Example</a></li>
<li><a href="#variables">Variables</a></li>
<li><a href="#heredoc">Heredoc Strings</a></li>
<li><a href="#operators">Operators</a></li>
<li><a href="#includef">Include Function</a></li>
<li><a href="#ifstatements">IF Statements</a></li>
<li><a href="#switchs">Switch Statements</a></li>
<li><a href="#userfunctions">User Defined Functions</a></li>
<li><a href="#arrays">Arrays</a></li>
<li><a href="#wloops">While Loops</a></li>
<li><a href="#floops">For Loops</a></li>
<li><a href="#formsusage">HTML Forms &amp; Using with PHP</a></li>
<li><a href="#mysqlandphp">MySQL &amp; PHP</a></li>
</ul>
</blockquote>
<h4><strong>PHP Examples</strong></h4>
<p>Let&#8217;s start learning. Open your text-editor or if you have dreamweaver installed, open a new file selecting Php. Don&#8217;t forget to save your file with the extension &#8220;.php&#8221; before putting into server.</p>
<blockquote><p><code><span style="color: #ff0000;">&lt;?php<br />
?&gt;</span></code></p></blockquote>
<p>This is a very basic php code. Php scripts, start with &#8220;&lt;?php&#8221; tag and end with &#8220;?&gt;&#8221; tag. While your server is reading that line starting with &#8220;&lt;?php&#8221;, it will know that a php script is starting, and it will compile and translate it to html.</p>
<p>In the above example, you see a commented line. Two slashes defines the following line as a comment. Server will ignore the line and will continue with the next line.</p>
<div id="hworld"><strong>HTML &amp; PHP &#8211; Hello World Example</strong></div>
<p>Below code demostrates the use of PHP with HTML. This code will print &#8220;Hello World&#8221; on the line php tag is, which will be inside the Html codes.</p>
<p>Save this code as &#8220;test.php&#8221;, put it into your server and access it using your internet browser. Server will compile and send you below html code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code8'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p68"><td class="code" id="p6code8"><pre class="html" style="font-family:monospace;">Hello World!</pre></td></tr></table></div>

<p>In that php script, we have printed inside of the quotation marks with php&#8217;s function &#8220;echo&#8221;. Echo is a function that outputs/prints the string defined in quotation marks. You also should know that string in PHP is defined inside quotation marks. In addition to this, pay attention to the semicolon at the end of the echo function. Every statement in php must be ended with semicolons.</p>
<p>A little more in the below example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p69"><td class="code" id="p6code9"><pre class="php" style="font-family:monospace;">Hello World<span style="color: #339933;">!</span><span style="color: #0000ff;">&quot;;
?&amp;gt;</span></pre></td></tr></table></div>

<p>When the server compiles the above code, it will generate the code below. The reason of using backslash before the quotation mark is to escape from quotation mark. Because first quotation mark starts the string and the second ends the string. If we do not escape from that quotation, the php script leads to an error since there is no function called &#8220;color&#8221; in php which is come after quotation. So we have to define all of the line with span tag and its inside as one <em>string</em>. This is done adding quotation marks at the beginning and also ending of the string. If the string, as in the above example, contains quotation marks, we do escape from that character using backslash (&#8221;\&#8221;).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code10'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p610"><td class="code" id="p6code10"><pre class="html" style="font-family:monospace;">&lt;span style=&quot;color: red;&quot;&gt;Hello World!&lt;/span&gt;</pre></td></tr></table></div>

<div id="variables"><strong>Variables in PHP</strong></div>
<p>Variables in php is defined by the beginning character of &#8220;$&#8221; and followed by the name of variable. Here is an example.</p>
<p>In the above code, there are three variables defined: site, days_in_week and weeks. Those are defined but will not printed unless you call and output them somewhere in your script. Here is an example demonstrating how we use them.</p>
<p>Two things are new to you at the above code. First, we defined a new variable multiplying two other variables. Multiplying numbers is done with &#8220;*&#8221; (Multiply) sign in php. The second one is inside of the echo function. We have combined three strings and printed. As you see, combining/joining two or mor variables is done by adding dots (.) besides of the variables. We may define a new variable by doing this. See this:</p>
<div id="heredoc"><strong>Heredoc String Creation</strong></div>
<p>There is an alternative way of defining strings in php. It is done by heredoc tool. Heredoc&#8217;s syntax is &lt;&lt;&lt;. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. Here is an example:</p>
<p>This code will be translated to the below code by the php server.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code11'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p611"><td class="code" id="p6code11"><pre class="html" style="font-family:monospace;">Example of string
spanning multiple lines
using heredoc syntax.</pre></td></tr></table></div>

<div id="operators"><strong>PHP Operators</strong></div>
<p>* Assignment Operators:<br />
Equal character, &#8220;=&#8221;, is used to assign variables,values or strings to variables.<br />
- $my_var=$your_var;</p>
<p>* Arithmetic Operators</p>
<ul>
<li>Addition +</li>
<li>Subtraction -</li>
<li>Multiplication *</li>
<li>Division /</li>
<li>Modulus %</li>
</ul>
<p>Here is an example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p612"><td class="code" id="p6code12"><pre class="php" style="font-family:monospace;">diff is <span style="color: #000088;">$diff</span>
mul is <span style="color: #000088;">$mul</span>
div is <span style="color: #000088;">$div</span>
mod is <span style="color: #000088;">$mod</span>
TEST<span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The server will output the below code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code13'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p613"><td class="code" id="p6code13"><pre class="html" style="font-family:monospace;">total is 6
diff is 4
mul is 24
div is 6
mod is 1</pre></td></tr></table></div>

<p>*Comparison Operators</p>
<table style="height: 130px;" border="1" cellspacing="1" cellpadding="1" width="100%" align="left">
<tbody>
<tr>
<th>Operator</th>
<th>English</th>
<th>Example</th>
<th>Result</th>
</tr>
<tr>
<td>==</td>
<td>Equal To</td>
<td>$x == $y</td>
<td>false</td>
</tr>
<tr>
<td>!=</td>
<td>Not Equal To</td>
<td>$x != $y</td>
<td>true</td>
</tr>
<tr>
<td>&lt;</td>
<td>Less Than</td>
<td>$x &lt; $y</td>
<td>true</td>
</tr>
<tr>
<td>&gt;</td>
<td>Greater Than</td>
<td>$x &gt; $y</td>
<td>false</td>
</tr>
<tr>
<td>&lt;=</td>
<td>Less Than or Equal To</td>
<td>$x &lt;= $y</td>
<td>true</td>
</tr>
<tr>
<td>&gt;=</td>
<td>Greater Than or Equal To</td>
<td>$x &gt;= $y</td>
<td>false</td>
</tr>
</tbody>
</table>
<div style="clear:both">Comparison operators are used for checking relationships of two variables or values. The result will be in true/false type. We&#8217;ll see the use of comparison operators later.</div>
<p>*Other Operators</p>
<table border="1" cellspacing="1" cellpadding="1" width="100%" align="left">
<tbody>
<tr>
<th>Operator</th>
<th>English</th>
<th>Example</th>
<th>Equivalent Operation</th>
</tr>
<tr>
<td>+=</td>
<td>Plus Equals</td>
<td>$x += 2;</td>
<td>$x = $x + 2;</td>
</tr>
<tr>
<td>-=</td>
<td>Minus Equals</td>
<td>$x -= 4;</td>
<td>$x = $x &#8211; 4;</td>
</tr>
<tr>
<td>*=</td>
<td>Multiply Equals</td>
<td>$x *= 3;</td>
<td>$x = $x * 3;</td>
</tr>
<tr>
<td>/=</td>
<td>Divide Equals</td>
<td>$x /= 2;</td>
<td>$x = $x / 2;</td>
</tr>
<tr>
<td>%=</td>
<td>Modulo Equals</td>
<td>$x %= 5;</td>
<td>$x = $x % 5;</td>
</tr>
<tr>
<td>.=</td>
<td>Concatenate Equals</td>
<td>$my_str.=&#8221;hello&#8221;;</td>
<td>$my_str = $my_str . &#8220;hello&#8221;;</td>
</tr>
<tr>
<td>++</td>
<td>Increment</td>
<td>$x++;</td>
<td>$x = $x + $x;</td>
</tr>
<tr>
<td>++</td>
<td>Decrement</td>
<td>$x&#8211;;</td>
<td>$x = $x &#8211; $x;</td>
</tr>
</tbody>
</table>
<div id="includef"><strong>Include Function</strong></div>
<p>PHP&#8217;s <em>include</em> is one of the most widely used functions. It simply, inserts the file defined into the php script. Meaning, you can use variables, functions and classes of the inserted file in your php script. Here is a simple example that will explain you more.</p>
<p><strong>vars.php:</strong></p>
<p><strong>index.php:</strong></p>
<p>Output of index.php would be following html code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code14'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p614"><td class="code" id="p6code14"><pre class="html" style="font-family:monospace;">Guest, Welcome to WoWebmaster.com</pre></td></tr></table></div>

<p>As you see, we used the variable defined in vars.php by including it in index.php.</p>
<div id="ifstatements"><strong>IF Statements</strong></div>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p615"><td class="code" id="p6code15"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>condition1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
statement1<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>condition2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
statement2<span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
statement3<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
nextline<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If statements, also, are one of the most widely used constructs of programming languages. If construct, is the important part of decision making algorithms. It allows conditional code execution. It checks whether a condition is true and the statement inside the construct is executed depending on the condition.</p>
<p>In the illustration above, <em>if</em> construct checks whether <em>condition1</em> is true, if so, <em>statement1</em> is executed, then <em>statement2</em> and <em>statement3</em> is ignored and the program jumps out of <em>if</em> construct, executing next line.</p>
<p>If <em>condition1</em> is false, then <em>condition2</em> is checked, if it is true, only <em>statement2</em> is executed before jumping to <em>nextline</em> statement. If <em>condition2</em> is also false, only <em>statement3</em> is executed.</p>
<p>An Example:</p>
<p>Now we will explain the example line by line. We defined a <em>$who</em> variable on the first line. It is a string containing &#8220;user&#8221;. In the second line, an <em>if</em> construct is defined. First condition to check is inside the first parenthesis which has <em>$who == &#8220;guest&#8221;</em> condition. If the variable, <em>$who</em>, equals to &#8220;quest&#8221;, then the statement defined inside the brackets is executed and without checking other conditions, program jumps out of <em>if</em> statements. In the example, <em>$who</em> does not equal to &#8220;guest&#8221;, instead, it equals to &#8220;user&#8221;. As a result, only <em>elseif</em> construct&#8217;s condition is executed, which outputs a &#8220;Welcome&#8221; on the screen.</p>
<p>Another Example:<br />
<strong>values.php:</strong></p>
<p><strong>index.php:</strong></p>
<p>In the example above, first, the program will check whether <em>$var</em> is 0, which is false, then the program will check the second condition which is also false. Since both conditions are not met, the program will only execute the last statement which is inside of <em>else</em> statement&#8217;s brackets. Following code is the output of the above code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code16'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p616"><td class="code" id="p6code16"><pre class="html" style="font-family:monospace;">No, the value is 3</pre></td></tr></table></div>

<div id="switchs"><strong>Switch Statements</strong></div>
<p>Switch is an alternative way of condition checking. With Switch statements, you can compare a same variable (or expression) against different cases quickly instead of using lots of elseif statements. Again, we will illustrate the use of it with an example:</p>
<p><em>Switch</em> statements compares a variable against cases defined, if one <em>case</em> is exactly the same with the variable, then only the statement under that <em>case</em> is executed. If no <em>case</em> equals to the variable then the statement under <em>default</em> line is executed. If you don&#8217;t write a break statement at the end of a case&#8217;s statement list, PHP will go on executing the statements of the following case.</p>
<div id="userfunctions"><strong>User Defined Functions</strong></div>
<p>Function is the name that is given to a special block of statements, when called, the block of statements are executed. Every function has a name, which you can call that special function anywhere in your script after defined.<br />
Defining a function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code17'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p617"><td class="code" id="p6code17"><pre class="php" style="font-family:monospace;">function_name <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Functions are usually used with parameters. Parameters appear in parantheses which is come after the function name and they can be used in the statements that function includes. Here is a usage example:<br />
<strong>index.php</strong>:</p>
<p>output:<br />
<code>:) world of webmaster</code></p>
<p>As seen above, the variable <em>$var</em> is defined as a parameter of <em>printing</em> function. This is done in the last line of the php script, <em>printing</em> function is called with the parameter <em>$var</em>. When called, the <em>printing</em> function accesses the value of <em>$var</em> using <em>$text</em> variable.</p>
<p>Some examples with the outputs below:<br />
<strong>functions.php</strong>:</p>
<p><strong>index.php</strong></p>
<p><strong>the output:</strong><br />
<code>In Total: $60.50</code></p>
<p>In the example above, we created a file, &#8220;functions.php&#8221;, that contain <em>calc</em> function. Our aim is to calculate the total price of a purchase. To simplify things, the purchase only comprises of tshirts. Our function <em>calc</em> has two parameters. First is tshirt&#8217;s price (<em>$tshirt</em>) and the second parameter is number of tshirts purchased (<em>$number</em>). Our <em>calc</em> function simply multiplies numbers by tshirt price and then adds the 10% tax.</p>
<p><strong>Functions Returning Values</strong><br />
Functions can also return values to the user. This is accomplished by adding &#8220;return <em>variable</em>;&#8221; at the end of the function. It&#8217;s easy, here is an example:</p>
<p><strong>output</strong>:<br />
<code><br />
<strong>Php Tutorials by Wowebmaster.com</strong><br />
</code></p>
<p>As seen above, <em>makebold()</em> function returned a value, which is a string, and we used that returning value by outputting (<em>echo</em>). Meaning, in the last line of code, <em>makebold</em> has a string value, that can be used like a variable.</p>
<p>One more example:</p>
<div id="arrays"><strong>Arrays</strong></div>
<p>An array is a data structure that stores different values in one variable. Each array in php, has a key and a corresponding value.</p>
<blockquote><p>$array_name[key]=value</p></blockquote>
<p>Key and Values of the array can be a string or number.</p>
<blockquote><p><strong>A numerically indexed array</strong><br />
$names[0]=&#8221;john&#8221;;<br />
$names[1]=&#8221;elizabeth&#8221;;<br />
$names[2]=&#8221;ahmed&#8221;;<br />
$names[3]=&#8221;michael&#8221;;<br />
$names[4]=&#8221;carmen&#8221;;</p></blockquote>
<p>$names variable is an array, and has a length of 5. This is quiet useful for storing data by grouping.</p>
<blockquote><p><strong>Associative Arrays</strong><br />
$ages["john"]=23;<br />
$ages["elizabeth"]=24;<br />
$ages["ahmed"]=21;<br />
$ages["michael"]=23;<br />
$ages["carmen"]=23;</p></blockquote>
<p>$ages variable is an array also, its keys are values (strings). Every key has associated with an age in this array. We will see usage examples after learning <em>loops</em> in php.</p>
<div id="wloops"><strong>While Loops</strong></div>
<p>While loops in php are continuous executing code blocks until a condition returns false.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p618"><td class="code" id="p6code18"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> condition <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
expression<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
somecode<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Here how loop works:</p>
<ul>
<li>1: <em>Condition</em> inside <em>while</em> statement is checked</li>
<li>2: If the <em>condition</em> is true, <em>expression</em> is executed, if false jump out of <em>while</em> loop and execute <em>somecode</em>.</li>
<li>3: Jump back to state 1, check the <em>condition</em> again.</li>
</ul>
<p>Above example, outputs numbers 1 to 10. Remember <em>$i++</em> means <em>$i=$i+1</em>. While $i is smaller than 10, $i is printed and then incremented. After incrementing, $i&lt;=10 condition is checked and the loop goes on until $i reaches 11.</p>
<p><strong>output:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code19'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p619"><td class="code" id="p6code19"><pre class="html" style="font-family:monospace;">john
carmen
elizabeth
robert
michael</pre></td></tr></table></div>

<p>Above example, prints an array&#8217;s elements with while loop. We now explain the script line by line.</p>
<ul style="text-align:left">
<li>On the first line, we started to fill an array by defining its first element, $values[0]=&#8221;john&#8221;. The numeric id starts with a zero &#8220;0&#8243;.</li>
<li>On the second, third, fourth and fifth lines, elements of the array are assigned in order. Those 5 lines also can achieved by <em>array</em> function, which is $values=array(&#8221;john&#8221;,&#8221;carmen&#8221;,&#8221;elizabeth&#8221;,&#8221;robert&#8221;,&#8221;michael&#8221;);.</li>
<li>Our loop&#8217;s counter, also used as key of our array, is assigned a starting value, which maps to the first element of the array.</li>
<li>On the seventh line, while loop starts with condition ($i&lt;5). If condition is not met, the program jumps to the 10th line (out of while loop).</li>
<li>Array&#8217;s current element is output on the 8nd line. <em>$i</em> is used as key of our array <em>$values</em>.</li>
<li>$i is incremented to point to the next element of the array.</li>
<li>Program returns to the seventh line again.</li>
</ul>
<p>From the above explanation, you should understand that the loop is repeated 5 times, outputting the corresponding element of the array within each loop.</p>
<div id="floops"><strong>For Loops</strong></div>
<p><em>For loops</em> in php is similar to <em>while loops</em>. The difference is that you set up your own loop counter with your condition beside.</p>
<p>This code, actually, does the same thing that the example of <em>while loop</em> does. In <em>for loops</em>, your counter&#8217;s initial value must be set inside of the parentheses and after placing your condition, you must also add a counter behavior, it can be $i++; $i&#8211; or something similar. At first execution of <em>for loop</em>, the initial value is set, and then in every loop, the condition is checked and counter&#8217;s behavior is executed.</p>
<div id="formsusage">
<h4>HTML Forms &amp; Usage</h4>
</div>
<p>Forms in web sites, are used to gather information from the visitors of website. In the example below, we will demonstrate a very easy html form, that gets the required information for a user to subscribe a website&#8217;s sources.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code20'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p620"><td class="code" id="p6code20"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;process.php&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;
&lt;label&gt;Your Name:
&lt;input name=&quot;name&quot; type=&quot;text&quot; /&gt;&lt;/label&gt;
&lt;label&gt;Your E-mail:
&lt;input name=&quot;email&quot; type=&quot;text&quot; /&gt;&lt;/label&gt;
&lt;label&gt;Subscription Type:
&lt;select name=&quot;type&quot;&gt;&lt;option&gt;Weekly&lt;/option&gt;&lt;option&gt;Monthly&lt;/option&gt;&lt;/select&gt;
&nbsp;
&lt;/label&gt;
&lt;input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p><strong>Output:</strong></p>
<blockquote><form action="process.php" enctype="multipart/form-data" method="post"> <label>Your Name:</label></p>
<input name="name" type="text" />
<label>Your E-mail:</label></p>
<input name="email" type="text" />
<label>Subscription Type:</label></p>
<select name="type"><option>Weekly</option><option>Monthly</option></select>
<input name="submit" type="submit" value="Submit" /> </form>
</blockquote>
<p>The form, asks for user to type his/her name, e-mail and subscription type. When the user hits the submit button, the form sends all the information using <em>multipart/form-data</em> encryption, to <em>process.php</em> with POST method.</p>
<p><strong>How to get the values sent by form?</strong><br />
With the POST method, sent values can be accessed using the associative array, $_POST. Allt the information, is assigned to $_POST, names of the form tags as keys, and the value of the form tags as values of the array. Here is how it is done.</p>
<p>If the user types his name as &#8220;John Mayer&#8221;, his e-mail as &#8220;john.mayer@hotmail.com&#8221; and his subscription type as &#8220;Weekly&#8221;. The output would be the following:</p>
<blockquote><p><code><br />
Hello John Mayer<br />
You have subscribed with the e-mail address: john.mayer@hotmail.com<br />
Subscription type: Weekly<br />
</code></p></blockquote>
<p>As seen above codes, our html form has 3 inputs, with names: <em>name</em>, <em>e-mail</em> and <em>type</em>. All of the values sent by form, is stored into the associative array, $_POST, as it did in our form: $_POST['name'], $_POST['e-mail'] and  $_POST['type'].</p>
<p><strong>GET Method</strong><br />
Another form of passing variables with a <em>form</em>, is <em>GET</em> method. Using this method, the html form, passes form variables by appending them into the url. Think we have three form inputs: <em>name</em>, <em>sirname</em> and <em>email</em>. When user submits the form, the url to go would be the following.</p>
<p><code>process.php?name=john&amp;sirname=mayer&amp;email=john.mayer@hotmail.com</code></p>
<p>All the variables in the url, is splitted with a &#8220;&amp;&#8221; sign and the question mark after file name, is to tell the web browser that the following items are variables. Here is an example form using <em>get</em> method.</p>
<p><strong>index.html:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code21'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p621"><td class="code" id="p6code21"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;process.php&quot; enctype=&quot;multipart/form-data&quot; method=&quot;get&quot;&gt;
&lt;label&gt;Purchase:
&lt;select name=&quot;shop&quot;&gt;&lt;option&gt;Tshirts&lt;/option&gt;&lt;option&gt;Books&lt;/option&gt;&lt;/select&gt;
&nbsp;
&lt;/label&gt;
&lt;label&gt;Quantity:
&lt;input name=&quot;quantity&quot; size=&quot;2&quot; type=&quot;text&quot; /&gt; &lt;/label&gt;
&lt;input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p><strong>output:</strong></p>
<blockquote><form action="process.php" enctype="multipart/form-data" method="get"> <label>Purchase:</label></p>
<select name="shop"><option>Tshirts</option><option>Books</option></select>
<p><label>Quantity:</label></p>
<input name="quantity" size="2" type="text" />
<input name="submit" type="submit" value="Submit" /> </form>
</blockquote>
<p><strong>url:</strong><br />
process.php?shop=Tshirts&amp;quantity=2</p>
<p><strong>process.php:</strong></p>
<p><strong>output:</strong><br />
You purchased 2 Tshirts.</p>
<p>In the above example, user, first, is asked to type what and how many he will buy. When he hits the submit button, the web browser will go to  <em>process.php?shop=Tshirts&amp;quantity=2</em> querying  process.php. Process.php will process the posted values, and output to the screen as seen above.</p>
<p>Now we go a little bit more. We will have one file, that has the form and also the form processor in. First we will examine if the user submitted the form, if so, the form processor script will be executed, if user did not submit any form, the file will again output the form to user&#8217;s screen. Here is the code:</p>
<p><strong>index.php:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p622"><td class="code" id="p6code22"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Purchase<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;shop&quot;</span><span style="color: #339933;">&gt;&lt;</span>option<span style="color: #339933;">&gt;</span>Tshirts<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;&lt;</span>option<span style="color: #339933;">&gt;</span>Books<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;&lt;/</span>select<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Quantity<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;quantity&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Submit&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
FORM<span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You have purchased &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'shop'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; .&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Thanks for choosing us! &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Form Submitted, Output:</strong><br />
You have purchased 2 Books .Thanks for choosing us!</p>
<p><strong>Form Not Submitted, Output:</strong></p>
<blockquote><form action="aq.php" enctype="multipart/form-data" method="post"> <label>Purchase:</label></p>
<select name="shop"><option>Tshirts</option><option>Books</option></select>
<p><label>Quantity:</label></p>
<input name="quantity" size="2" type="text" />
<input name="Submit" type="submit" value="Submit" /> </form>
</blockquote>
<p>The above code, first checks if user submitted the form, if not, the script outputs $form which has the form in, else, the script accesses &#8220;posted&#8221; variables using $_POST and executes the required processes.</p>
<div id="mysqlandphp">
<h4>Mysql &amp; Usage in PHP</h4>
</div>
<p>We&#8217;ve seen to gather information using html forms. However the important thing is to store this information in a database, to reach whenever needed. Mysql is the most widely used database to store information in PHP. So now, we&#8217;re going to demonstrate the usage of mysql and php together.</p>
<p><strong>Connecting to a MySQL database</strong><br />
It can be done with two functions, <em>mysql_connect</em> and <em>mysql_pconnect</em> (persistent connection).</p>
<p>In the above code, mysql connection is created using mysql_connect function, &#8220;localhost&#8221; is the name of server (it can be an IP either), &#8220;mysql_user&#8221; and &#8220;mysql_password&#8221; are username and password of mysql installation on the server.</p>
<p><strong>MySQL Tables</strong><br />
MySQL tables, are like associative arrays in someway, every row of the table has an index that corresponds to a value. That is to store values and sort them.</p>
<blockquote>
<table border="1" width="100%">
<tbody>
<tr>
<th>Id</th>
<th>E-mail</th>
<th>Subscription Type</th>
</tr>
<tr>
<td>1</td>
<td>someone@someone.com</td>
<td>Weekly</td>
</tr>
<tr>
<td>2</td>
<td>someone2@someone.com</td>
<td>Monthly</td>
</tr>
<tr>
<td>3</td>
<td>someone3@someone.com</td>
<td>Monthly</td>
</tr>
<tr>
<td>4</td>
<td>someone4@someone.com</td>
<td>Weekly</td>
</tr>
<tr>
<td>5</td>
<td>someone5@someone.com</td>
<td>Monthly</td>
</tr>
</tbody>
</table>
</blockquote>
<p>Above table, can be shown as a sample mysql table. In mysql, when 4th row is selected on this table, all the column values can be associated with an array, which you can use later.</p>
<p>So how do we create tables using php? Not hard, here is an example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code23'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p623"><td class="code" id="p6code23"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">';
mysql_select_db(&quot;database_name&quot;);  // selecting a database
mysql_query(&quot;CREATE TABLE subscribers(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), email VARCHAR(30), type VARCHAR(30))&quot;);
mysql_close($link);
?&amp;gt;</span></pre></td></tr></table></div>

<p>Line by line, explanation of the above code:</p>
<ul>
<li>First, we create a mysql connection, <em>localhost</em> is the host name, <em>mysql_user</em> and <em>mysql_password</em> are login information of mysql database. <em>Mysql connection</em>&#8217;s status is assigned to <em>$link</em> variable. <em>Mysql_connect</em> function returns a MySQL link identifier on success, or FALSE on failure.</li>
<li>With the <em>IF conditional statement</em> block, <em>mysql connection</em> is checked. If there is no connection ($link=false); the php script will end the program with <em>die</em> function.</li>
<li>If there is a connection to mysql database, the program will go on executing <em>echo</em> function, which will output <em>&#8220;Connected Successfully&#8221;</em>.</li>
<li> mysql_query() sends a unique query to the currently active database ($link) on the server. The query on the above code creates a table with columns: id, e-mail and type. Id is defined to have integer numbers (int), email and type columns can have varchar type.</li>
<li>On the last line, mysql connection is closed with <em>mysql_close</em> function.</li>
</ul>
<p><strong>Mysql Training: Widely Used Queries</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p624"><td class="code" id="p6code24"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;CREATE TABLE subscribers (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), e-mail VARCHAR(30), type VARCHAR(30))&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Subscribers table created, columns: id, e-mail,type */</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;DELETE FROM subscribers WHERE e-mail='someone1@someone.com' LIMIT 1&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/*someone1@someone.com's all information is removed from the database */</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;INSERT INTO subscribers (id, e-mail, type) VALUES ('', 'someone1@someone.com', 'weekly');&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/*Inserting new subscriber on subscribers database. id is auto incremented based on the previous row, e-mail and type will have values, someone1@someone.com and weekly*/</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UPDATE subscribers SET e-mail='someone1@domain.net', type='monthly' WHERE id='113' LIMIT 1;&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">/*Updating a row*/</span>
&nbsp;
<span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT * FROM subscribers&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// All subscribers selected</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT * FROM subscribers WHERE type='Weekly'&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">/* Weekly subscribers selected*/</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT id,email FROM subscribers WHERE type='Monthly'&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">/* Monthly subscribers' id and email columns are selected */</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SELECT * FROM subscribers WHERE type='Monthly' LIMIT 0, 5&quot;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">/*5 Montly subscribers selected */</span></pre></td></tr></table></div>

<p>Ok, now you&#8217;ve seen some widely used queries above, we can go further with a complex example.</p>
<p><strong>Example: Subscriber Form &amp; List</strong></p>
<p>If you haven&#8217;t understood the code on the above examples, you may get a better idea of how mysql works, in this example. We will have three files, one for creating a table, one for your users to subscribe your website and one for you to list all the subscribers.</p>
<p><em>Create_Table.php</em><br />
The first step to form a subscriber system, is to have a mysql table for it. Let&#8217;s store our subscribers&#8217; name, e-mail and subscription type. To sort our list, we should also need an ID for every user. Hence, we create a table with id, name, e-mail and type columns. Here is the php script to create this table.</p>
<p><em>Subscribe.php</em><br />
In this file, we have an if conditional statement which will be checking if the form submitted, if submitted, all the data is stored on the mysql, if not submitted, the subscription form will be printed on the screen.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p625"><td class="code" id="p6code25"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">&gt;</span>Type Your Name<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;name&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;15&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;e-mail&quot;</span><span style="color: #339933;">&gt;</span>Type Your E<span style="color: #339933;">-</span><span style="color: #990000;">mail</span><span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;15&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #339933;">&gt;</span>Subscription Type<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>select name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #339933;">&gt;&lt;</span>option<span style="color: #339933;">&gt;</span>Weekly<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;&lt;</span>option<span style="color: #339933;">&gt;</span>Monthly<span style="color: #339933;">&lt;/</span>option<span style="color: #339933;">&gt;&lt;/</span>select<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Submit&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
FORM<span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As seen above, storing a data on mysql is easy. First, a connection is established with mysql server, then a database is selected with <em>mysql_select_db()</em> function. The last thing is to execute the desired query using <em>mysql_query()</em> function.</p>
<p><em>What does addslashes do?</em><br />
Prior to PHP 6, there was a feature called <em>magic quotes</em> that was created to help protect programmers from writing bad form processing code. Magic quotes automatically escapes from risky form data that might be used for SQL Injection with a backslash \. The characters escaped by PHP include: quote &#8216;, double quote &#8220;, backslash \ and NULL characters. In other words, a hacker, may type something in your form to reach your private SQL database. For instance; if you don&#8217;t use addslashes to add backslashes into the user written text, you might be hacked with this:</p>
<blockquote><p><strong>Hacker&#8217;s input:</strong><br />
username: hacker<br />
password: &#8216; OR 1</p>
<p><strong>Your PHP Script:</strong><br />
<span style="color: red;">mysql_query(&#8221;SELECT * FROM users WHERE username=&#8217;$username&#8217; and password=&#8217;$password&#8217;&#8221;);</span></p>
<p><small>above code would be the following which always returns a row that will result the hacker log in</small><br />
<span style="color: red;">mysql_query(&#8221;SELECT * FROM users WHERE username=&#8217;hacker&#8217; and password=&#8221; OR 1&#8242;&#8221;);</span></p>
<p><small>using addslashes, your query would be the following, which will not return any result</small><br />
<span style="color: red;">mysql_query(&#8221;SELECT * FROM users WHERE username=&#8217;hacker&#8217; and password=&#8217;\&#8217; OR 1\&#8217;&#8221;);</span></p></blockquote>
<p><em>Subscribers.php</em><br />
Our aim is to list all the subscribers in order with their information. We will sort them with their ids in subscribers.php. Therefore, we have to use the SELECT query which will select all the subscribers sorting with their ids. So, how do we output the results? It&#8217;s a little bit tricky. We first fetch the result into an associative array using the function: <em>mysql_fetch_row()</em>, and output the array using <em>while</em> loop.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p626"><td class="code" id="p6code26"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$id</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$type</span>
<span style="color: #990000;">LIST</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If we look closer, our mysql query has a <em>&#8220;ORDER BY id ASC&#8221;</em> part. This is to arrange the results in ascending order. Results, are assigned to an associative array. This array has 4 corresponding column results of mysql. For example, <em>$row['name']</em>, is assigned with a new value of <em>&#8216;name&#8217;</em> column, depending on the index of <em>$result</em>, which is incremented at the beginning of every loop. Therefore, in every loop, a different row is printed with <em>echo</em> function using <em>heredoc</em> tool.</p>
<blockquote><p><small><strong>Stripslashes:</strong> Remember we added back slashes to escape from risky data before storing our data on mysql. So we use <em>stripslashes</em> function to remove added slashes.</small></p></blockquote>
<p>Now, we&#8217;ll go further with our subscription system. Yes, we have a form for our users to subscribe our web site and we have a web page to see all our subscribers. Now, we&#8217;ll modify our <em>subscribers.php</em> to email our newsletter to each subscriber. Sounds good? Yes.</p>
<p>Mods to do:</p>
<ul>
<li>A text box to write e-mail</li>
<li>A select box to select subscribers to mail</li>
<li>IF statement to check if form is submitted</li>
<li>Mail function inside while statement, one by one mailing</li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p6code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p627"><td class="code" id="p6code27"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">&gt;</span>E<span style="color: #339933;">-</span><span style="color: #990000;">mail</span><span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;&lt;</span>textarea cols<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;10&quot;</span> rows<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;6&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">&gt;&lt;/</span>textarea<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Fwww.wowebmaster.com%2Fphp%2Flearn-php-by-examples%2F&amp;linkname=Learn%20PHP%20by%20Examples"><img src="http://www.wowebmaster.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.wowebmaster.com/php/learn-php-by-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
