<?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>Unlikely Teacher &#187; PHP</title>
	<atom:link href="http://unlikelyteacher.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://unlikelyteacher.com</link>
	<description>1. Share Everything* [Programming Gotchas, Technology News, Insights on Living and Everything in Between]</description>
	<lastBuildDate>Fri, 03 Sep 2010 04:12:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Fatal error: Call to undefined function wp_dashboard_setup()</title>
		<link>http://unlikelyteacher.com/2010/03/24/fatal-error-call-to-undefined-function-wp_dashboard_setup/</link>
		<comments>http://unlikelyteacher.com/2010/03/24/fatal-error-call-to-undefined-function-wp_dashboard_setup/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 02:58:57 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[A2 Hosting]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://unlikelyteacher.com/?p=535</guid>
		<description><![CDATA[I got this error in WordPress this morning when trying to logon to the Admin pages: Fatal error: Call to undefined function wp_dashboard_setup() in /home/username/public_html/wp-admin/index.php on line 15 I didn&#8217;t make any changes or upgrades to the site and the weird part is that all of a sudden, two of our WordPress installations were displaying [...]]]></description>
			<content:encoded><![CDATA[<p>I got this error in WordPress this morning when trying to logon to the Admin pages:</p>
<p><code>Fatal error: Call to undefined function wp_dashboard_setup() in /home/username/public_html/wp-admin/index.php  on line 15</code></p>
<p>I didn&#8217;t make any changes or upgrades to the site and the weird part is that all of a sudden, two of our WordPress installations were displaying this error.</p>
<p><strong>UPDATE</strong>: March 24, 10:12 PM GMT+8 It looks like the problem is related to A2 Hosting changing the default PHP version (see Neil&#8217;s post in the comments section).</p>
<p>I did some Googling and found a <a href="http://florent.clairambault.fr/wordpress-with-apc">workaround</a>.</p>
<p>The solution is to change this line in wp-admin/index.php:</p>
<p><code>require_once(ABSPATH . 'wp-admin/includes/dashboard.php');</code></p>
<p>to this line:</p>
<p><code>require_once('./includes/dashboard.php');</code></p>
<p>I&#8217;m still trying to investigate the cause of the problem but in the meantime, hope this quick fix solves your problem.</p>
<p>Thanks to Florent for sharing his solution. And thanks also to Neil for providing the reason for the error and a better approach to handling the problem for those who are with A2 Hosting.</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2010/03/24/fatal-error-call-to-undefined-function-wp_dashboard_setup/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP writeUTF implementation</title>
		<link>http://unlikelyteacher.com/2009/05/12/php-writeutf-implementation/</link>
		<comments>http://unlikelyteacher.com/2009/05/12/php-writeutf-implementation/#comments</comments>
		<pubDate>Tue, 12 May 2009 04:02:50 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[pack()]]></category>

		<guid isPermaLink="false">http://dayg.slingandstoneweb.com/?p=371</guid>
		<description><![CDATA[We currently have an application in Groovy/Grails/Java that we&#8217;re slowly porting to PHP (for more affordable hosting costs). We encountered a problem when we needed to convert one of our routines for writing out a binary file. We were using Java&#8217;s DataOutputStream.writeUTF(String) method and had a hard time trying to write binary data in PHP. [...]]]></description>
			<content:encoded><![CDATA[<p>We currently have an application in Groovy/Grails/Java that we&#8217;re slowly porting to PHP (for more affordable hosting costs).</p>
<p>We encountered a problem when we needed to convert one of our routines for writing out a binary file. We were using Java&#8217;s DataOutputStream.writeUTF(String) method and had a hard time trying to write binary data in PHP.</p>
<p>After much research on the web, we found a method in PHP called <a href="http://www.php.net/pack">pack()</a>. Below is our PHP implementation of Java&#8217;s DOS.writeUTF(String).</p>
<pre class="brush: php">
	public static function writeUTF($string) {
		$utfString = utf8_encode($string);
		$length = strlen($utfString);
		print(pack(&quot;n&quot;, $length));
		print($utfString);
		flush();
	}
</pre>
<p>We don&#8217;t claim this to be the exact equivalent of the method, but it gets the job done and the receiving end of the file was able to parse the binary file properly with the new PHP implementation with no modifications to the client code.</p>
<p>Please checkout the <a href="http://www.php.net/pack">pack(</a>) documentation for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2009/05/12/php-writeutf-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework Large File Upload Issues</title>
		<link>http://unlikelyteacher.com/2009/02/03/zend-framework-large-file-upload-issues/</link>
		<comments>http://unlikelyteacher.com/2009/02/03/zend-framework-large-file-upload-issues/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 10:27:30 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Form_Element_File]]></category>

		<guid isPermaLink="false">http://dayg.slingandstoneweb.com/?p=314</guid>
		<description><![CDATA[I tried modifying this Zend_Form_Element_File example to support larger file uploads but noticed that I&#8217;ve been getting &#8220;Undefined index&#8221; errors when my uploads are bigger than 8MB. Notice: Undefined index: tmp_name in C:\quickstart\library\Zend\File\Transfer\Adapter\Abstract.php on line 589 Notice: Undefined index: name in C:\quickstart\library\Zend\Validate\File\Size.php on line 398 Notice: Undefined index: tmp_name in C:\quickstart\library\Zend\File\Transfer\Adapter\Abstract.php on line 589 Notice: [...]]]></description>
			<content:encoded><![CDATA[<p>I tried modifying this <a href="http://framework.zend.com/manual/en/zend.form.standardElements.html#zend.form.standardElements.file">Zend_Form_Element_File example</a> to support larger file uploads but noticed that I&#8217;ve been getting &#8220;Undefined index&#8221; errors when my uploads are bigger than 8MB.</p>
<blockquote><p>Notice: Undefined index: tmp_name in C:\quickstart\library\Zend\File\Transfer\Adapter\Abstract.php on line 589</p>
<p>Notice: Undefined index: name in C:\quickstart\library\Zend\Validate\File\Size.php on line 398</p>
<p>Notice: Undefined index: tmp_name in C:\quickstart\library\Zend\File\Transfer\Adapter\Abstract.php on line 589</p>
<p>Notice: Undefined index: name in C:\quickstart\library\Zend\Validate\File\Extension.php on line 228</p></blockquote>
<p>Being a PHP and Zend Framework newbie, I wanted to put the blame on Zend but in the end I found the reason for the upload and validation errors after much googling.</p>
<p>The solution requires updating two properties in <a href="http://devzone.zend.com/manual/ini.core.html#ini.post-max-size">php.ini</a>:</p>
<blockquote><p>
upload_max_filesize = 32M<br />
post_max_size = 32M
</p></blockquote>
<p>With these changes you can now upload relatively bigger files!</p>
<p>Just make sure that your <a href="http://www.a2hosting.com/1701-max-upload-size-237-custom.html">hosting provider supports your file upload size settings</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2009/02/03/zend-framework-large-file-upload-issues/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress Thank a Plugin Developer Day</title>
		<link>http://unlikelyteacher.com/2009/01/29/wordpress-thank-a-plugin-developer-day/</link>
		<comments>http://unlikelyteacher.com/2009/01/29/wordpress-thank-a-plugin-developer-day/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 03:58:56 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sitemap]]></category>
		<category><![CDATA[Syntax Highlighter]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://dayg.slingandstoneweb.com/2009/01/29/wordpress-thank-a-plugin-developer-day/</guid>
		<description><![CDATA[Yesterday, I tried working on my first ever WordPress plugin. It&#8217;s a simple filter which includes a Google Adsense script after every post. I&#8217;m thinking of creating a Buy me a Coffee plugin next to take this plugin development challenge on to the next level. Coincidentally, Matt just announced January 28 as the official WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I tried working on my first ever WordPress plugin. It&#8217;s a simple filter which includes a Google Adsense script after every post.</p>
<p>I&#8217;m thinking of creating a Buy me a Coffee plugin next to take this plugin development challenge on to the next level.</p>
<p>Coincidentally, Matt just announced January 28 as the official <a href="http://wordpress.org/development/2009/01/thank-a-plugin-developer-day/">WordPress Thank a Plugin Developer Day</a>.</p>
<p>Hopefully next year my plugins would be included in the next 4000 plugins for WordPress.</p>
<p>But for now, I&#8217;d like to thank the developers of <a href="http://wordpress.org/extend/plugins/google-sitemap-generator/">Google Sitemap Generator</a> and <a href="http://wordpress.org/extend/plugins/syntaxhighlighter-plus/">Syntax Highlighter Plus</a> for a job well done.</p>
<p>Keep up the good work you guys!</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2009/01/29/wordpress-thank-a-plugin-developer-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO basics</title>
		<link>http://unlikelyteacher.com/2008/09/19/seo-basics/</link>
		<comments>http://unlikelyteacher.com/2008/09/19/seo-basics/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 10:10:35 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://dayg.wordpress.com/?p=194</guid>
		<description><![CDATA[I&#8217;ve been creating web applications for quite some time but never got interested in SEO (or Search Engine Optimization) until now. The primary reason I think is that most (if not all) of the web applications I&#8217;ve been developing are for internal use only (think Java and banks). But this outlook changed as my wife [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been creating web applications for quite some time but never got interested in SEO (or Search Engine Optimization) until now.</p>
<p>The primary reason I think is that most (if not all) of the web applications I&#8217;ve been developing are for internal use only (think Java and banks).</p>
<p>But this outlook changed as my wife and I started playing with a Christian Music Site called <a href="http://www.slingandstonemusic.com/">Sling &amp; Stone Music</a>.</p>
<p>For starters, I&#8217;ve converted most of the dynamic URLs to use mod_rewrite to somehow make them search friendly.</p>
<p>I was thinking of buying a book for this purpose but luckily I found some very good articles from <a href="http://www.ibm.com/developerworks/">IBM developerWorks</a> on the said topic.</p>
<p>Here are the links:</p>
<ul>
<li><a href="http://www.ibm.com/developerworks/web/library/wa-seo1.html">Search engine optimization basics, Part 1: Improve your standing in search engines</a></li>
<li><a href="http://www.ibm.com/developerworks/web/library/wa-seo2/">Search engine optimization basics, Part 2: SEO keyword and infrastructure strategies</a></li>
<li><a href="http://www.ibm.com/developerworks/web/library/wa-seo3.html">Search engine optimization basics, Part 3: Get your Web pages into search indexes</a></li>
<li><a href="http://www.ibm.com/developerworks/web/library/wa-seo4.html">Search Engine Optimization basics, Part 4: Improve search marketing for large sites</a></li>
</ul>
<p>Hope you find them useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2008/09/19/seo-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache 2.2 and mod_rewrite</title>
		<link>http://unlikelyteacher.com/2008/07/10/apache-22-and-mod_rewrite/</link>
		<comments>http://unlikelyteacher.com/2008/07/10/apache-22-and-mod_rewrite/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 09:17:35 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache 2.2]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://dayg.wordpress.com/?p=123</guid>
		<description><![CDATA[This is a super short (and very rough) post on how to enable mod_rewrite in Apache 2.2. I have seen numerous posts on how to create &#8220;rewrite&#8221; scripts but found very little information on how to enable this feature in Apache 2.2. Step 1: Uncomment the line with &#8220;mod_rewrite.so&#8221; from httpd.conf LoadModule rewrite_module modules/mod_rewrite.so Step [...]]]></description>
			<content:encoded><![CDATA[<p>This is a super short (and very rough) post on how to enable mod_rewrite in Apache 2.2.</p>
<p>I have seen numerous posts on how to create &#8220;rewrite&#8221; scripts but found very little information on how to enable this feature in Apache 2.2.</p>
<p>Step 1: Uncomment the line with &#8220;mod_rewrite.so&#8221; from httpd.conf</p>
<blockquote><p>LoadModule rewrite_module modules/mod_rewrite.so</p></blockquote>
<p>Step 2: Search for the keyword &#8220;.htaccess&#8221; and change the AllowOverride value</p>
<blockquote><p>AllowOverride All</p></blockquote>
<p>Step 3: Restart Apache and check if module has been loaded (LoadedModule section in phpinfo())</p>
<p>Step 4: Create a test .htaccess in your root directory</p>
<blockquote><p>Options +Indexes<br />
Options +FollowSymlinks<br />
RewriteEngine on<br />
RewriteBase /<br />
RewriteRule ^success\.html$ index.php [L]</p></blockquote>
<p>Step 5: Type http://localhost/success.html in your browser (change port info based on your setup)</p>
<p>You should be able to see your index.php load up.</p>
<p>Recommended book:</p>
<p><a href="http://www.amazon.com/gp/product/1590595610/104-2616196-5897505?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1590595610"><img src="http://rcm-images.amazon.com/images/I/51oEkibQT2L._SL75_.jpg" border="0" alt="1590595610" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2008/07/10/apache-22-and-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Sling and Stone Music is Now Online</title>
		<link>http://unlikelyteacher.com/2008/06/13/sling-and-stone-music-is-now-online/</link>
		<comments>http://unlikelyteacher.com/2008/06/13/sling-and-stone-music-is-now-online/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 06:54:19 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sunday School]]></category>
		<category><![CDATA[Christian Music]]></category>
		<category><![CDATA[Christianity]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Music Videos]]></category>

		<guid isPermaLink="false">http://dayg.wordpress.com/?p=112</guid>
		<description><![CDATA[After several weeks of not being able to post here regularly, I&#8217;m very happy to announce that the initial release of Sling and Stone Music is now online. Sling and Stone Music is about &#8220;Discovering God&#8217;s Love through Music&#8221;. Watch Music Videos (some with lyrics) from various Christian artists. Artist information, albums and lyrics are [...]]]></description>
			<content:encoded><![CDATA[<p>After several weeks of not being able to post here regularly, I&#8217;m very happy to announce that the initial release of <a href="http://www.slingandstonemusic.com/" target="_blank">Sling and Stone Music</a> is now online.</p>
<blockquote><p>Sling and Stone Music is about &#8220;Discovering God&#8217;s Love through Music&#8221;. Watch Music Videos (some with lyrics) from various Christian artists. Artist information, albums and lyrics are retrieved from Crossmap.com, Amazon.com and Christianlyricsonline.com respectively.</p></blockquote>
<p>Feel free to send comments and suggestions to our <a href="http://www.assembla.com/spaces/sas-music/tickets" target="_blank">Assembla space</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2008/06/13/sling-and-stone-music-is-now-online/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some &quot;Really Neat&quot; PHP Resources</title>
		<link>http://unlikelyteacher.com/2008/05/29/some-really-neat-php-resources/</link>
		<comments>http://unlikelyteacher.com/2008/05/29/some-really-neat-php-resources/#comments</comments>
		<pubDate>Thu, 29 May 2008 07:56:34 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SimpleXML]]></category>

		<guid isPermaLink="false">http://dayg.wordpress.com/?p=110</guid>
		<description><![CDATA[I&#8217;m currently working on a personal PHP project and I just wanted to sort of &#8220;bookmark&#8221; the resources I&#8217;ve gathered and found useful over the past few days. SimpleXML processing with PHP PHP Cookbook Using PHP 5&#8242;s SimpleXML User Registration/Account Activation Script Object Oriented PHP: Paging Result Sets Write to a file from PHP This [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a personal PHP project and I just wanted to sort of &#8220;bookmark&#8221; the resources I&#8217;ve gathered and found useful over the past few days.</p>
<ul>
<li><a href="http://www.ibm.com/developerworks/library/x-simplexml.html" target="_blank">SimpleXML processing with PHP</a></li>
<li><a href="http://www.onlamp.com/pub/a/php/2004/01/15/simplexml.html" target="_blank">PHP Cookbook Using PHP 5&#8242;s SimpleXML</a></li>
<li><a href="http://www.tutorialcode.com/php/registration-script/" target="_blank">User Registration/Account Activation Script</a></li>
<li><a href="http://www.sitepoint.com/article/php-paging-result-sets/5?nocache=1254883871" target="_blank">Object Oriented PHP: Paging Result Sets</a></li>
<li><a href="http://php.about.com/od/advancedphp/ss/file_write_php.htm" target="_blank">Write to a file from PHP</a></li>
</ul>
<p>This is just my second PHP project and I feel like I&#8217;m beginning to like PHP better and better by the day.</p>
<p>Hope you also find these resources &#8220;really neat&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2008/05/29/some-really-neat-php-resources/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP 101: A Simple Seat Reservation System</title>
		<link>http://unlikelyteacher.com/2008/04/17/php-101-a-simple-seat-reservation-system/</link>
		<comments>http://unlikelyteacher.com/2008/04/17/php-101-a-simple-seat-reservation-system/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 02:55:55 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dayg.wordpress.com/?p=79</guid>
		<description><![CDATA[I would like to share a little application I developed last year for a simple concert that our church sponsored. The requirement was to develop a seat/ticket reservation system which will be accessed from two different locations. The application will be used by administrators only to check the available seats and will not be accessible [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to share a little application I developed last year for a simple concert that our church sponsored.</p>
<p>The requirement was to develop a seat/ticket reservation system which will be accessed from two different locations.</p>
<p>The application will be used by administrators only to check the available seats and will not be accessible to end users.</p>
<p><strong>UPDATE: 8/7/10</strong></p>
<blockquote><p>Demo site is currently down, moving to a new server.</p></blockquote>
<p><a href="http://dayg.files.wordpress.com/2008/04/tickets-zip.odt">Download link</a> (make sure to rename the downloaded file to .zip instead of .odt)</p>
<p>Database Design:</p>
<pre>
<pre class="brush: sql">

CREATE TABLE seats (
   rowId varchar(1) not null,
   columnId int not null,
   status int,
   updatedby varchar(10),
   PRIMARY KEY (rowId,columnId)
);

CREATE TABLE userauth (
   rowID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
   commonname VARCHAR(35) NOT NULL,
   username VARCHAR(8) NOT NULL,
   pswd VARCHAR(32) NOT NULL,
   PRIMARY KEY(rowID)
);
</pre>
</pre>
<p>I tried to make the tables as simple as possible.</p>
<p>For the seats table, I used the rowId and columnId columns as the PK. The status column represent the state of a particular seat (0-available, 1-reserved, 2-confirmed). The updatedby column is for storing the name of the user who last updated the record (importance of this column will be discussed later).</p>
<p>I also needed some form of authentication which is contained in the userauth table. I think the columns for this table are self-explanatory, so there&#8217;s really no need to go into more detail about that.</p>
<p>I created a login.php page for authentication. I had to embed this page to all the other pages which I wanted to protect from unauthorized access.</p>
<pre>
<pre class="brush: php">

function authenticate_user() {
   header(&#039;WWW-Authenticate: Basic realm=&quot;Tickets&quot;&#039;);
   header(&quot;HTTP/1.0 401 Unauthorized&quot;);
   exit;
}
</pre>
</pre>
<p>If you try to access a page which invokes the fragment above then you will be presented with a screen similar to what is shown below:</p>
<p><a href="http://dayg.files.wordpress.com/2008/04/auth-ie.png"><img class="aligncenter size-medium wp-image-80" src="http://dayg.files.wordpress.com/2008/04/auth-ie.png" alt="" width="276" height="300" /></a></p>
<p>A word of caution from the <a href="http://www.amazon.com/gp/product/1590598628/105-9788505-2474000?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1590598628" target="_blank">Beginning PHP and MySQL 5</a> book:</p>
<blockquote><p>Note that unless output buffering is enabled, these commands must be executed before<br />
any output is returned. Neglecting this rule will result in a server error, because of the violation<br />
of the HTTP specification.</p></blockquote>
<p>You can retrieve the values entered into this form through the following scripts:</p>
<pre>
<pre class="brush: php">

$_SERVER[PHP_AUTH_USER] // for retrieving username
$_SERVER[PHP_AUTH_PW] // for retrieving password
</pre>
</pre>
<p>The values retrieved from the form are then compared to the entries in the userauth table. And if no match is found, the login form is re-displayed to the user.</p>
<pre>
<pre class="brush: php">

// Connect to the MySQL database
mysql_pconnect(&quot;localhost&quot;, &quot;tickets&quot;, &quot;tickets&quot;)
   or die(&quot;Can&#039;t connect to database server!&quot;);
mysql_select_db(&quot;tickets&quot;) or die(&quot;Can&#039;t select database!&quot;);

// Check for matching users
$query = &quot;SELECT username, pswd FROM userauth&quot;
   . &quot; WHERE username=&#039;$_SERVER[PHP_AUTH_USER]&#039;&quot;
   . &quot; AND pswd=&#039;$_SERVER[PHP_AUTH_PW]&#039;&quot;;
$result = mysql_query($query);

// Re-display login form
if (mysql_num_rows($result) == 0) {
authenticate_user();
}
</pre>
</pre>
<p>I do hope all these snippets still make sense to you because we are just about to proceed to the more complicated stuff.</p>
<p>Given the seat layout of the concert hall, I decided to represent the rows using letters and the columns as numbers. The tricky part was how to dynamically generate the seat layout based on the rows retrieved from the seats DB table.</p>
<p style="text-align: center;"><a href="http://dayg.files.wordpress.com/2008/04/seats.png"><img class="aligncenter size-thumbnail wp-image-81" src="http://dayg.files.wordpress.com/2008/04/seats.png?w=128" alt="" width="232" height="144" /></a></p>
<p>The next fragments were taken from seats.php</p>
<pre>
<pre class="brush: php">

// Select all the seats in the venue
// The seat numbers in the concert hall were read from right to left
// (which is why columnId is sorted as desc)
$query = &quot;SELECT * from seats order by rowId, columnId desc&quot;;
$result = mysql_query($query);

// Iterate through results, assign values to rowId, columnId,
// status and updatedBy variables
while (list($rowId, $columnId, $status, $updatedby)
   = mysql_fetch_row($result))
</pre>
</pre>
<p>We now begin with the fun part, for every seat, which is still available, create a checkbox. For every seat which is reserved, also create a checkbox only if the user currently logged in is also the same user who reserved the seat. You may be wondering, why do I need to create a checkbox for a seat that&#8217;s already reserved? This is because, in this application, the reserved state is not the final state for a seat. A reserved seat can still be canceled or confirmed. But once a reserved seat is confirmed, no further modifications can be made to that seat.</p>
<pre>
<pre class="brush: php">
echo &quot;&lt;td bgcolor=&#039;$seatColor&#039; align=&#039;center&#039;&gt;&quot;;
echo &quot;$rowId$columnId&quot;;

if ($status == 0
   || ($status == 1
      &amp;amp;amp;amp;&amp;amp;amp;amp; $updatedby == $_SERVER[&#039;PHP_AUTH_USER&#039;])) {
   echo &quot;&lt;input type=&#039;checkbox&#039; name=&#039;seats[]&#039;&quot;
      . &quot; value=&#039;$rowId$columnId&#039; /&gt;&quot;;
</pre>
</pre>
<p style="text-align: center;"><a href="http://dayg.files.wordpress.com/2008/04/seats-colors.png"><img class="aligncenter size-thumbnail wp-image-82" src="http://dayg.files.wordpress.com/2008/04/seats-colors.png?w=128" alt="" width="249" height="159" /></a></p>
<p>From PHP, we step back a bit and discuss the JavaScript part of the code which is as important as the PHP scripts.</p>
<pre>
<pre class="brush: javascript">
	function reserveSeats() {

		var selectedList = getSelectedList(&#039;Reserve Seats&#039;);

		if (selectedList) {
			if (confirm(&#039;Do you want to reserve selected seat/s &#039; + selectedList + &#039;?&#039;)) {
				document.forms[0].oldStatusCode.value=0;
				document.forms[0].newStatusCode.value=1;
				document.forms[0].action=&#039;bookseats.php&#039;;
				document.forms[0].submit();
			} else {
				clearSelection();
			}
		}
	}

	function cancelSeats() {

		var selectedList = getSelectedList(&#039;Cancel Reservation&#039;);

		if (selectedList) {
			if (confirm(&#039;Do you want to cancel reserved seat/s &#039; + selectedList + &#039;?&#039;)) {
				document.forms[0].oldStatusCode.value=1;
				document.forms[0].newStatusCode.value=0;
				document.forms[0].action=&#039;bookseats.php&#039;;
				document.forms[0].submit();
			} else {
				clearSelection();
			}
		}
	}

	function confirmSeats() {

		var selectedList = getSelectedList(&#039;Confirm Reservation&#039;);

		if (selectedList) {
			if (confirm(&#039;Do you want to confirm reserved seat/s &#039; + selectedList + &#039;?&#039;)) {
				document.forms[0].oldStatusCode.value=1;
				document.forms[0].newStatusCode.value=2;
				document.forms[0].action=&#039;bookseats.php&#039;;
				document.forms[0].submit();
			} else {
				clearSelection();
			}
		}
	}
</pre>
</pre>
<p>You will notice that there are three main functions (reserveSeats(), cancelSeats() and confirmSeats()) for modifying a seat&#8217;s status.</p>
<p>These scripts submit the values of the HTML FORM in seats.php to another PHP page named bookseats.php. This bookseats page is particularly interested in three FORM parameters from the seats page namely, oldStatusCode, newStatusCode and the seats array generated by the checkboxes.</p>
<p>An example of the request would be:</p>
<p>oldStatusCode=0<br />
newStatusCode=1<br />
seats[A1,A2,B3]</p>
<p>Which means Reserve the currently Available A1, A2 and B3 seats.</p>
<p>It is important to note the behavior of checkboxes in HTML. Only the values of &#8220;selected&#8221; checkboxes get submitted when you make a POST request. You can retrieve request parameters in PHP using $_GET for GET requests and$_POST for POST requests.</p>
<p>The bookseats page is divided into two parts. The first part checks whether the seats are still in the same state (no changes were done to the seats by another user while we were busy doing something else) prior to making any updates.</p>
<pre>
<pre class="brush: php">

// dynamically build select statement

$selectQuery = &quot;SELECT rowId, columnId from seats where (&quot;;
$count = 0;
foreach($_POST[&#039;seats&#039;] AS $seat) {
if ($count &gt; 0) {
$selectQuery .= &quot; || &quot;;
}
$selectQuery .= &quot; ( rowId = &#039;&quot; . substr($seat, 0, 1) . &quot;&#039;&quot;;
$selectQuery .= &quot; and columnId = &quot; . substr($seat, 1) . &quot; ) &quot;;
$count++;
}

$selectQuery .= &quot; ) and status = $oldStatusCode&quot;;
if ($oldStatusCode == 1) {
$selectQuery .= &quot; and updatedby = &#039;$user&#039;&quot;;
}

// execute select statement
$result = mysql_query($selectQuery);

$selectedSeats = mysql_num_rows($result);
if ($selectedSeats != $count) {
$problem = &quot;
&lt;h3&gt;There was a problem executing your request. No seat/s were updated.&lt;/h3&gt;
&quot;;
die ($problem);
}
</pre>
</pre>
<p>If the system detects any concurrent updates then it stops with step 1, displays an error message to the user and does not proceed with step 2.</p>
<p>The second part performs the actual database update after necessary checks from step 1 have been processed.</p>
<pre>
<pre class="brush: php">

// prepare update statement
$newStatusCode = $_POST[&#039;newStatusCode&#039;];
$oldStatusCode = $_POST[&#039;oldStatusCode&#039;];

$updateQuery = &quot;UPDATE seats set status=$newStatusCode, updatedby=&#039;$user&#039; where ( &quot;;
$count = 0;
foreach($_POST[&#039;seats&#039;] AS $seat) {
 if ($count &gt; 0) {
 	$updateQuery .= &quot; || &quot;;
 }
 $updateQuery .= &quot; ( rowId = &#039;&quot; . substr($seat, 0, 1) . &quot;&#039;&quot;;
 $updateQuery .= &quot; and columnId = &quot; . substr($seat, 1) . &quot; ) &quot;;
 $count++;
}
$updateQuery .= &quot; ) and status = $oldStatusCode&quot;;
if ($oldStatusCode == 1) {
 $updateQuery .= &quot; and updatedby = &#039;$user&#039;&quot;;
}

// perform update
$result = mysql_query($updateQuery);
$updatedSeats = mysql_affected_rows();

if ($result &amp;amp;amp;&amp;amp;amp; $updatedSeats == $count) {
 echo &quot;&lt;h3&gt;&quot;
 echo &quot;You have successfully updated $updatedSeats seat/s: &quot;;
 echo &quot;[&quot;;
 foreach($_POST[&#039;seats&#039;] AS $seat) {
 	$rowId = substr($seat, 0, 1);
 	$columnId = substr($seat, 1);
 	echo $rowId . $columnId . &quot;, &quot;;
 }
 echo &quot;]&quot;;
 echo &quot;...&lt;/h3&gt;&quot;;
}
</pre>
</pre>
<p>This application represents my first attempt into the PHP world and I must say that there are still a lot of improvements that can be added to this quick and dirty solution.</p>
<p>For one, the user can create his own login form instead of relying in the browser&#8217;s basic login form (shown earlier).</p>
<p>A logout option would be a very worthy addition and can be achieved by simply adding a link which calls the session_destroy() directive.</p>
<p>Styles and scripts can also be moved to external CSS and external JavaScript files.</p>
<p>Anyway, I still hope I was able to provide you enough details about PHP to serve as starting point.</p>
<p>Feel free to download (and rename to .zip) the <a href="http://dayg.files.wordpress.com/2008/04/tickets-zip.odt">application</a> and modify to your own liking.</p>
<p>Recommended books:</p>
<p><a href="http://www.amazon.com/gp/product/1590598628/102-5933529-6312909?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1590598628"><img src="http://rcm-images.amazon.com/images/I/51z9UQnTL6L._SL75_.jpg" border="0" alt="1590598628" /></a> <a href="http://www.amazon.com/gp/product/0596009763/104-2616196-5897505?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0596009763"><img src="http://rcm-images.amazon.com/images/I/51WGCcUi9uL._SL75_.jpg" border="0" alt="0596009763" /></a><a href="http://www.amazon.com/gp/product/0596101996/104-2616196-5897505?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0596101996"><img src="http://rcm-images.amazon.com/images/I/51dIXs2B1LL._SL75_.jpg" border="0" alt="0596101996" /></a><strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2008/04/17/php-101-a-simple-seat-reservation-system/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>Beginning PHP and MySQL 5 for $10</title>
		<link>http://unlikelyteacher.com/2008/04/12/beginning-php-and-mysql-5-for-10/</link>
		<comments>http://unlikelyteacher.com/2008/04/12/beginning-php-and-mysql-5-for-10/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 01:25:07 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[e-books]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://dayg.wordpress.com/?p=72</guid>
		<description><![CDATA[At 12:01 AM PST, a different Apress or friends of ED eBook will be priced at $10 US for a 24-hour period You can view/purchase the discounted e-books from this URL: http://www.apress.com/info/dailydeal. About the same time last year, I needed to create a simple Ticket Reservation System for a small concert in our local church. [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>At 12:01 AM PST, a different Apress or friends of ED eBook will be priced at $10 US for a 24-hour period</p></blockquote>
<p>You can view/purchase the discounted e-books from this URL: <a href="http://www.apress.com/info/dailydeal" target="_blank">http://www.apress.com/info/dailydeal</a>.</p>
<p>About the same time last year, I needed to create a simple Ticket Reservation System for a small concert in our local church. There were two locations were tickets can be ordered and they wanted the available seats to updated real-time. I needed a quick and affordable solution so I decided to use PHP and MySQL to implement this functionality.</p>
<p>Coming from ZERO PHP knowledge, I used this book below as reference and it helped me develop a simple solution in just a couple of days.</p>
<p><a href="http://www.amazon.com/gp/product/1590595521/105-9154790-5245259?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1590595521"><img src="http://rcm-images.amazon.com/images/I/51aDQNXGSrL._SL75_.jpg" border="0" alt="1590595521" /></a> <strong> <a href="http://www.amazon.com/gp/product/1590595521/105-9154790-5245259?ie=UTF8&amp;tag=doasyogo-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1590595521">Beginning PHP and MySQL 5</a> </strong></p>
<p>You can get this e-book from Apress for $10 until tomorrow 12 mn PST.</p>
]]></content:encoded>
			<wfw:commentRss>http://unlikelyteacher.com/2008/04/12/beginning-php-and-mysql-5-for-10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
