<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Garage developer's Blog</title>
	<atom:link href="http://garagedeveloper.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://garagedeveloper.wordpress.com</link>
	<description>Just another development blog</description>
	<lastBuildDate>Thu, 18 Aug 2011 17:34:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='garagedeveloper.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Garage developer's Blog</title>
		<link>http://garagedeveloper.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://garagedeveloper.wordpress.com/osd.xml" title="Garage developer&#039;s Blog" />
	<atom:link rel='hub' href='http://garagedeveloper.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The DIY Surveillance System Using a Webcam – Part 3</title>
		<link>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-3/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-3/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 22:53:13 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[C# interfacing with arduino]]></category>
		<category><![CDATA[C# Serial communication]]></category>
		<category><![CDATA[C# timer events]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=101</guid>
		<description><![CDATA[Im going to assume you have read the Part-1 and Part-2 of this post. Part-1 provides the hardware and Part-2 with the software for streaming and controlling the camera. This part will focus on the php file which is generated by the PHP webpage and its usage by the microcontroller to move or pan the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=101&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Im going to assume you have read the <a href="http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-part-1/">Part-1</a> and <a href="http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-2/">Part-2</a> of this post. Part-1 provides the hardware and Part-2 with the software for streaming and controlling the camera. This part will focus on the php file which is generated by the PHP webpage and its usage by the microcontroller to move or pan the camera. Lets get started.</p>
<p>Firstly we need a host program to read the data generated by the PHP and poll our “request” folder created in part-2 for updated data. Then we need to transmit this information serially to the microcontroller which pans based on that information. Im using C# to create this host program so here it goes. Start Visual Studio create a windows application. Throw in a button, a combo box and timer control. The stop button would stop the timer which will be initiated by the combo box changed event.</p>
<p><span id="more-101"></span>The code looks like:</p>
<pre class="brush: csharp;">

namespace RotomaticFront

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Loader(object sender, EventArgs e)

{

string[] aFilenames;

string fileName;

byte[] buf = null;

aFilenames = Directory.GetFiles(&quot;C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Rotomatic\\request\\&quot;);

if (aFilenames.Length &gt; 0)

{

fileName = Path.GetFileNameWithoutExtension(aFilenames[0]);

StreamReader SR;

string S;

SR = File.OpenText(&quot;C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Rotomatic\\request\\&quot; + fileName);

S = SR.ReadLine();

SR.Close();

File.Delete(aFilenames[0]);

SerialPort port = new SerialPort(comboBox1.SelectedItem.ToString(), 9600, Parity.None, 8, StopBits.One);

port.Open();

port.Write(dirr[1]);

//port.Write(angl[1]);

port.Close();

}

}

private void Form1_Load(object sender, EventArgs e)

{

foreach (string s in SerialPort.GetPortNames())

{

comboBox1.Items.Add(s);

}

}

private void button1_Click(object sender, EventArgs e)

{

timer1.Stop();

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{

timer1.Interval = 1000;

timer1.Start();

}

}
</pre>
<p>Lets start with the form_load() event. I populate the combo box with the com ports which are available on the system. Since the arduino board is connected to one of the com ports and I have a lot of usb/com conversions going on I have a lot of ports which keep changing, you might not have this problem so you can skip it, it’s entirely up to you.</p>
<p>Once the combo box index changes a timer is initiated with a 1 second interval and the event that is triggered on each tick is the Loader() event I will explain its working in a bit. The stop button simply stops the timer. The Loader event gets the file names in the request directory first, if the length of the files is &gt;0 means a file is there, the file name is then acquired without the extension. The file is opened and the first line is read ( since we only wrote only one line we don’t need to do a while loop but you might need to if you add other options). The file is then closed and deleted. A serial port connection is opened at 9600 baud and the data read is transmitted serially to the arduino board/microcontroller. I keep saying microcontroller and not the arduino board because the end device to control the motor could be a PIC or any other microcontroller it doesn’t necessarily have to be the arduino board.</p>
<p>Thats it run the program make sure everything is working throw in a couple of message boxes while reading the data to make sure you are actually reading the right data.</p>
<p>Now lets move onto the code for the micro controller. For those who don’t know the code is written in arduino programming language based on C/C++. Here is the code:</p>
<pre class="brush: cpp;">

int dirPin  = 4;

int stepperPin= 3;

int sleepPin=7;

int ledPin=8;

char dir;

void setup () {

pinMode (dirPin, OUTPUT);

pinMode (stepperPin, OUTPUT);

pinMode(sleepPin,OUTPUT);

pinMode(ledPin,OUTPUT);

Serial.begin(9600);

Serial.flush();

}

void step(boolean dir,int steps){

digitalWrite(sleepPin,HIGH);

digitalWrite(dirPin,dir);

delay(50);

for(int i=0;i&lt;steps;i++){

digitalWrite(stepperPin, HIGH);

delayMicroseconds(100);

digitalWrite(stepperPin, LOW);

delayMicroseconds(100);

}

digitalWrite(sleepPin,LOW);

}

void loop(){

dir=' ';

if (Serial.available()) {

dir=Serial.read();

if(dir=='1'){

step(true,15);

digitalWrite(ledPin,HIGH);

//delay(500);

}

if(dir=='0'){

step(false,15);

digitalWrite(ledPin,LOW);

//delay(500);

}

}

}
</pre>
<p>The basic function for stepping is the same and was mentioned in part-1. The only new thing is the LED on PIN 8 for determining the direction of pan. The setup() function consists of a Serial.begin(9600) which initiates the serial communication followed by the baud rate settings. The Loop() function which is the arduino equivalent of C main() with the only difference as the name suggests, it keeps looping forever. Anyway Serial.availible() checks if there is any serial data to be read on the serial port. If there is it is read by serial.read() and stored in the dir variable. If the direction is one the clockwise rotation is turned on and 15 steps are taken in the clockwise direction – step(true,15)  . The opposite is true if a 0 is read from the serial port. LED turns high for the clockwise rotation and off for the anti-clockwise rotation. Its a good indicator as it helps to see data coming through is correctly being read. Load the program to the arduino board and your done.</p>
<p>Run the PHP webpage along with the streaming server ( “simpleSubscriber”) . Try panning and it should work and there you have it a surveillance system from a webcam :]. I would’ve  provided you with a URL to mine but its installed at my work place!!!! So I cant let me install one at home and then ill post a link. Ill also try to get a video of it going anyway, please post any questions you have in the comments section followed by the part you are having problems with or cant understand. Till then happy coding!.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=101&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>
	</item>
		<item>
		<title>The DIY Surveillance System Using a Webcam – Part 2</title>
		<link>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-2/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-2/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 22:46:35 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[PHP-AJAX]]></category>
		<category><![CDATA[FLV Streaming]]></category>
		<category><![CDATA[Red5 Confuguration]]></category>
		<category><![CDATA[Red5 Streaming]]></category>
		<category><![CDATA[Red5 with Arduino]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=91</guid>
		<description><![CDATA[If you are reading this without reading the part 1 of this post I suggest you give that a read before starting with this since its gives the basic hardware needed to get everything going. However if your requirements are a simple streaming server with a client read on. There are two modules within this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=91&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are reading this without reading the <a href="http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-part-1/">part 1</a> of this post I suggest you give that a read before starting with this since its gives the basic hardware needed to get everything going. However if your requirements are a simple streaming server with a client read on.</p>
<p>There are two modules within this post aswell I wont bother splitting them up into two rather just go on describing them in one. The first one is the streaming server with a client which serves the need for our surveillance. The second part includes the PHP webpage which includes the streaming client followed by code to generate a request file telling the motor which direction to rotate in.</p>
<p><span id="more-91"></span></p>
<p>Streaming Server:  Ill start off with the server which is needed to stream video from a webcam. Im using Red5 which as an open source alternative to the flash media server and is written in java. It supports shared objects, flv streaming and a lot more. Details of this can be obtained from <a href="http://osflash.org/red5">http://osflash.org/red5</a>.  Red5 uses RTMP (real time messaging protocol) to transmit video and data over the internet between a flash player and a server and therefore it is ideal for multiplayer flash games. Infact it provides some demos when you install it which covers the details of shared objects and other neat stuff. Since I’ve effectively touched the installation bit id simply go on and describe the process. It took me a while to understand and get going with red5 and couldn’t find much help for it. Things you need before you can install and get going with red5:</p>
<p>1- Java SE 1.6 SE its available to download from their website and you can get it from <a href="http://java.sun.com/javase/">http://java.sun.com/javase/</a></p>
<p>Since red5 is written in java you need it to make it all work.</p>
<p>2- Tomcat – Optional read below</p>
<p>Now there are two paths from here either install Tomcat run the Red5 as a server on it or use the installer provided by Red5 which embeds tomcat and runs Red5 as a service. This phenomenon is summarized in the images below:</p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/12/tomcat-red5.jpg"><img class="alignleft size-full wp-image-92" title="Tomcat-Red5" src="http://garagedeveloper.files.wordpress.com/2009/12/tomcat-red5.jpg?w=261&#038;h=177" alt="" width="261" height="177" /></a></p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/12/red5-tomcat.jpg"><img class="alignright size-full wp-image-93" title="Red5-Tomcat" src="http://garagedeveloper.files.wordpress.com/2009/12/red5-tomcat.jpg?w=265&#038;h=208" alt="" width="265" height="208" /></a></p>
<p>If you chose the first path then you have to download the Red5 “War” file and place it in tomcats the “webapps” folder where it would be extracted automatically, this type of installation is explained in more detail here: <a href="http://osflash.org/red5/windowstomcat%20">http://osflash.org/red5/windowstomcat</a> . I chose the latter but I did try the other one as well and for some reason my demos would not work on that so I decided to go with the installer. Note even with the Installer you do need the Java SE. Once you have done that by default the server is hosted on port 8080 so typing <a href="http://localhost:8080/">http://localhost:8080</a> should show you a red5 welcome page.</p>
<p>Now if you get an error on localhost go to windows-&gt;services and check for Red5 and make sure its running. If its not make sure you have the right Java sdk I’m using 1.6 along with the installer for that version. You can change the port its running on by going to the directory where you installed red5-&gt;conf-&gt;Red5.properties file. In here you will see different settings, look at the one which says HTTP and it is the port where http requests are served, change this to whatever you like. RTMP is set to 1935 which is the default standard port for RTMP but you can change this to whichever ones are available on your system.</p>
<p>I had a lot of problems with these since my apache server and Red5 were on the same port and wouldn’t get along. Then I changed the ports but I still could not access them. The reason came out to be that I was behind University Firewall (don’t ask ) and the ports were blocked so I had to get them open to get all of this going! A pain but someone has to do it. Make sure you don’t have these firewall problems.</p>
<p>The Server:</p>
<p>Now for the streaming server, well once youve installed Red5 now you should be able to view the demos. Go to the demo page and there is one called “simpleBroadcaster”. These demos are open source and come with the flash source so you can do all sorts of things with them. Once you are at the demo page, enter the ip address or localhost if you want to run it locally and click connect. The 5 symbol should turn green and you should be able to see your camera. If that is the case your server is working along with the RTMP port. If youve used something other than 1935 for the RTMP you would have to run the broadcaster as “rtmp://localhost:port/oflaDemo”.</p>
<p>The Client:</p>
<p>Similarly within the same demo’s page open another browser page and open simpleSubscriber. Enter the IP address or localhost and click the connect button. Now you should be able to view the stream. Its that simple. You can also use the clients which provide support to view RTMP streams. One can be found at: <a href="http://www.longtailvideo.com/">http://www.longtailvideo.com/</a> which allows you to configure the player online and generate code to embed in your webpage’s. I’m using the one which comes with the Red5 server.</p>
<p>The webpage:</p>
<p>I copied the swf file for the simpleSubscriber which is present in the Red5 into my apache web server folder where I will create the page embedding the client. Here is the code:</p>
<pre class="brush: plain;">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;

&lt;head&gt;

&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;

&lt;title&gt;Rotomatic&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;script&gt;

swfobject.embedSWF(&quot;simpleSubscriber.swf&quot;, &quot;myContent&quot;, &quot;400&quot;, &quot;400&quot;, &quot;8.0.0&quot;, &quot;assets/expressInstall.swf&quot;);

&lt;/script&gt;

&lt;div align=&quot;right&quot; &gt;

&lt;h1&gt;You need the Adobe Flash Player for this demo, download it by clicking the image below.&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;&lt;img src=&quot;http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif&quot; alt=&quot;Get Adobe Flash player&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
</pre>
<p>The swfobject.embedSWF embeds the swf into the webpage, there is an extra “assets/expressInstall.swf” which is a support to allow users visiting the webpage to install flash player or update it without leaving the webpage. You can embed you own player here like the one I mentioned earlier provided by Longtail which can be configured online along with the code to embed it.</p>
<p>The Remaining Webpage:</p>
<p>Now for the rest of the page. Im going to create two simple buttons one to allow the camera to be panned to the right and the other to pan to the left. When these buttons are clicked a file is generated in a request folder. This file contains either a 0 or a 1. “0” for a clockwise rotation and “1” for an anticlockwise rotation. Pretty stupid creating a file with such information right?. Not really it can later be configured to allow auto panning options of the camera along with angle values and other neat stuff. Im using JQuery (sorry Sajax fans but I mentioned I was going to move to JQuery) to transfer data from my webpage to the PHP script that writes the file. The code for the main page is as follows:</p>
<pre class="brush: php;">

&lt;?php

session_start();

$PHPSESSID = session_id();

include(&quot;rwfile.php&quot;);

?&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;

&lt;head&gt;

&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;

&lt;title&gt;Rotomatic&lt;/title&gt;

&lt;script src=&quot;scripts/jquery.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;scripts/jquery.ajaxmanager.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;assets/swfobject.js&quot;&gt;&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;script&gt;

var ajaxManager1 = $.manageAjax({manageType: 'abortOld', maxReq: 10});

var dirc;

function send(){

ajaxManager1.add({   success: function(html)

{

},

type: &quot;POST&quot;,

url: &quot;rwfile.php&quot;,

data:      &quot;dir=&quot; + dirc

});

}

function incrementAngle(){

dirc=0;

send();

}

function decrementAngle(){

dirc=1;

send();

}

swfobject.embedSWF(&quot;simpleSubscriber.swf&quot;, &quot;myContent&quot;, &quot;400&quot;, &quot;400&quot;, &quot;8.0.0&quot;, &quot;assets/expressInstall.swf&quot;);

&lt;/script&gt;

&lt;div align=&quot;right&quot; &gt;

&lt;h1&gt;You need the Adobe Flash Player for this demo, download it by clicking the image below.&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;&lt;img src=&quot;http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif&quot; alt=&quot;Get Adobe Flash player&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;

&lt;div align=&quot;left&quot;&gt;

&lt;label&gt;Camera Panning&lt;/label&gt;

&lt;br&gt;

&lt;input type=&quot;button&quot; onclick=&quot;decrementAngle();&quot;value=&quot;&lt;&lt;&quot;&gt;

&lt;input onclick=&quot;incrementAngle();&quot; value=&quot;&gt;&gt;&quot;&gt;

&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
</pre>
<p>The include(&#8220;rwfile.php&#8221;);  file holds the PHP script which will we will see in a bit and is responsible for writing the text file holding the direction information. The other two within the script tags are the standard JQuery files while the swfObject is for the express installer. The functions incrementAngle() and decrementAngle() simply set the values of the dirc variable and performing a post operation to rwfile.php for writing the file. The code above also includes the streaming client code.</p>
<p>The code for the  “rwfile.php” looks something like this:</p>
<pre class="brush: php;">

&lt;?php

session_start();

$PHPSESSID = session_id();

writeRequestFile();

function writeRequestFile()

{

if(!is_dir(&quot;request&quot;))

{

mkdir(&quot;request&quot;) or die(&quot;Could not create request directory&quot;);

}

if(!is_dir(&quot;request\\temp&quot;))

{

mkdir(&quot;request\\temp&quot;) or die(&quot;Could not create request directory&quot;);

}

$id=session_id();

if(is_file(&quot;request\\{$id}&quot;))

{

unlink(&quot;request\\{$id}&quot;);

}

if(@$fh = fopen(&quot;request\\temp\\{$id}&quot;,&quot;w&quot;))

{

$dir=$_POST[&quot;dir&quot;];

$angle=$_POST[&quot;Angle&quot;];

fwrite($fh,&quot;dir=$dir\r\n&quot;);

fwrite($fh,&quot;angle=$angle\r\n&quot;);

fclose($fh);

}else

{

return FALSE;

}

return rename(&quot;request\\temp\\{$id}&quot;,&quot;request\\{$id}&quot;);

}

?&gt;
</pre>
<p>The session is used as a file name to which holds the direction values. First it is ensured if the “request” directory exists along with a temp directory whose purpose is explained below, if they don’t exist they are created. If a file exists within the request directory with the same session id it is deleted the unlink command performs this operation. The files are initially written to a temp directory within the request folder. This is just a safety measure to ensure the file is not written while already one is being created with the same session id, since the event occurs on a button click some users might go crazy pressing the button. The ending code is a return call with a rename which moves the temp file to the request directory.</p>
<p>That’s all for the web page front end. Now I will describe how the file created by the PHP is handled by the host program followed by the code for the microcontroller in Part 3 – The communication module. So if you’re still interested move to part 3.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=91&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-%e2%80%93-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/12/tomcat-red5.jpg" medium="image">
			<media:title type="html">Tomcat-Red5</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/12/red5-tomcat.jpg" medium="image">
			<media:title type="html">Red5-Tomcat</media:title>
		</media:content>
	</item>
		<item>
		<title>The DIY Surveillance System Using a Webcam &#8211; Part 1</title>
		<link>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-part-1/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-part-1/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 22:31:34 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[PHP-AJAX]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Easy Driver]]></category>
		<category><![CDATA[Stepper Motor Sparkfun]]></category>
		<category><![CDATA[Surveillance Using Webcam]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=74</guid>
		<description><![CDATA[Part-1:  Hardware The Story: Its been a while since my last post due to some work projects which have been occupying a lot of time and effort. However I still managed to find time for a hobby project, a DIY surveillance system using a webcam so I thought I’d go and share it with the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=74&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://garagedeveloper.files.wordpress.com/2009/12/camera_mount-1.jpg"><img class="alignnone size-full wp-image-87" title="camera_mount-1" src="http://garagedeveloper.files.wordpress.com/2009/12/camera_mount-1.jpg?w=497&#038;h=745" alt="" width="497" height="745" /></a></p>
<p>Part-1:  Hardware</p>
<p>The Story: Its been a while since my last post due to some work projects which have been occupying a lot of time and effort. However I still managed to find time for a hobby project, a DIY surveillance system using a webcam so I thought I’d go and share it with the rest. It’s not really a hobby project the real motivation behind the project are some of the cleaners which mess up some of the wirings of some work related project I am involved in. So you’d leave everything okay and when you come back in the morning something would either be unplugged or just not working. I’d  to spend a lot of time probing on the scope of what’s wrong and most important where! with so many wires it’s a pain.  So I decided to go ahead with building a surveillance system for myself using a webcam and some other hardware which I will mention in a while (I don’t want to go in detail of why not buy one off the shelf so don’t ask). The project however did help me learn about some valuable electronics concepts and it wasn’t all for fun. Anyway without further delay id just get on with it.</p>
<p><span id="more-74"></span></p>
<p>Id cover this project in three parts:</p>
<p>1-      The hardware</p>
<p>2-      The comms (communication with the hardware)</p>
<p>3-      The software (web based control including streaming)</p>
<p>The second one is also related to software but since its more about channelling communication down to the hardware I decided to keep it separate.  The flow of this entire process is summarized in the diagram below.</p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/12/flow_diagram2.jpg"><img class="alignnone size-full wp-image-76" title="Flow_Diagram" src="http://garagedeveloper.files.wordpress.com/2009/12/flow_diagram2.jpg?w=497&#038;h=141" alt="" width="497" height="141" /></a></p>
<p>I would start off with the hardware part which is crucial as if that doesn’t work, there is no point to the rest of it really. The hardware that is needed for the projects include:</p>
<p>1-      Webcam</p>
<p>2-      Stepper Motor (4 wired  = 2 Coils for a clockwise and an 2 for anticlockwise rotation)- <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9238">http://www.sparkfun.com/commerce/product_info.php?products_id=9238</a></p>
<p>3-      Motor Driver Board (Controlling the motor why this is needed is discussed below)-<a href="http://www.flickr.com/photos/45253805@N07/4156919912/">http://www.sparkfun.com/commerce/product_info.php?products_id=9402</a></p>
<p>4-      Arduino Board (any would do I’m using which has the ATmega168 on it. Description below)</p>
<p>Webcam is pretty obvious since its a surveillance system so cant do much without the video I guess. The webcam I am using is:</p>
<p><a href="http://www.flickr.com/photos/45253805@N07/4156146981/">http://www.flickr.com/photos/45253805@N07/4156146981/</a></p>
<p>The stepper motor was a bit tricky to decide on compared with servos. But to summarize it down for those who don’t know much about it is that servos operate on a closed loop and perform a feedback mechanism to the microcontroller to adjust position errors in other words they aren’t that precise. So say I want the camera to be at a 45 degree angle id have to rely on the feedback from the motor to first decide where it is and then move on to adjust the position. Stepper motors are however are relatively cheap and provide precision control by operating in steps. A complete discussion on servos vs steppers is discussed here and is worth having a look at <a href="http://www.torchmate.com/motors/electronics_selection.htm">http://www.torchmate.com/motors/electronics_selection.htm</a>. The motor for this project can be viewed at the link above and is a bipolar motor. The stepper motor: (<a href="http://www.flickr.com/photos/45253805@N07/4156919912/">http://www.flickr.com/photos/45253805@N07/4156919912/</a>)</p>
<p>The stepper driver is the A3967SLB and can be viewed at the link above which is used to control motor movement and provide precision control based on the input pulses provided to it. It can be operated in full-, half-, quarter-, and eighth-step modes. For people who still don’t understand just consider it as way to translate the high/low pulses into something meaningful for the motor to move a step a very small if it’s just 1 pulse. The driver(<a href="http://www.flickr.com/photos/45253805@N07/4156920162/">http://www.flickr.com/photos/45253805@N07/4156920162/</a>)</p>
<p>The last but not the least is the arduino board which has the Atmega168 microcontroller on it. This is needed as it talks to the stepper driver which in turn controls the movement on the motor.</p>
<p>Connecting it all up:</p>
<p>1- Camera to the stepper motor</p>
<p>Ok so now we know the basic components of what are going to use so lets get on with the connections and how all of this will work. The first thing was to cut the camera (you can see the image at the flickr link mentioned above) and make it fit on the motor. Now this is a very crucial yet very important procedure so make sure you don’t damage the camera. I cannot exactly go about telling how to cut it up but here are some of the snaps of how the camera is mounted on the motor:</p>
<p>1-      <a href="http://www.flickr.com/photos/45253805@N07/4156920424/in/photostream/">http://www.flickr.com/photos/45253805@N07/4156920424/in/photostream/</a> &#8211; Side view</p>
<p>2-      <a href="http://www.flickr.com/photos/45253805@N07/4156158481/in/photostream/">http://www.flickr.com/photos/45253805@N07/4156158481/in/photostream/</a> &#8211; Back view</p>
<p>Once this is done plug the camera within the USB port to make sure its working!!! Else you’ve done something wrong or damaged the camera J.</p>
<p>2-  The Stepper Driver – Motor Connection</p>
<p>The simplified diagram of the stepper is as follows, it only includes only the pins I am using</p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/12/stepper-simplified1.jpg"><img class="alignnone size-full wp-image-78" title="Stepper-simplified" src="http://garagedeveloper.files.wordpress.com/2009/12/stepper-simplified1.jpg?w=497&#038;h=241" alt="" width="497" height="241" /></a></p>
<p>The 5v and the Gnd are to run the driver board. Instead of using a power supply for this what I did was use the pins on the arduino to get the 5v directly. This powers the driver.  The PWR is the power to the motor and can be from 12v to 30v. Im using 12v to power it from an external power supply. The C-A and C-B are the coils from the stepper motor in other words the 4 wires from the stepper motor would go in here. If you are using a motor different than the one mentioned above please read the data sheet to ensure that the correct wires are placed. In total there are 4 coils within the motor 2 to ensure a clockwise rotation and 2 to ensure an anticlockwise rotation. If these wires are attached in a wrong order the clockwise and the anticlockwise motion might cancel each other out and the motor might not move. The connections for the motor above are as follows:</p>
<p>Red and Green are for Coil A – C-A</p>
<p>Yellow and Blue are for Coil B – C-B</p>
<p>So now you would have the motor connected to the stepper driver board.</p>
<p>3- Stepper Driver- Arduino Connections</p>
<p>Ive connected the dir pin which controls the direction of the motor to Pin 4 on the arduino and the stepperPin which controls the amount of steps the motor should take is connected to Pin 3.The sleep pin is connected to Pin 7</p>
<p>My connections: <a href="http://www.flickr.com/photos/45253805@N07/4161441034/">http://www.flickr.com/photos/45253805@N07/4161441034/</a></p>
<p>Why connect the sleep pin?</p>
<p>Ok this is important because it allows the coil which holds the shaft in its position, to demagnetise. What I mean is if you don’t use the sleep pin the motor still functions but if you try to move it with your hand you wouldn’t be able to since the coils are magnetised and they hold the shaft firmly. Since the coils are magnetised this causes the motor to heat up and I didn’t want that to happen if the motor is not in operation else it would melt the glue that is holding the camera.</p>
<p>Test Software:</p>
<p>Now to ensure everything is alright and the motor is working upload the following test code which is a basic routine which comes with the driver to see if everything is working or not. I’ve added a bit to control the sleep pin you may wish to remove this to observe what happens without the sleep pin. This code is written with the arduino programming language which is based on c/c++</p>
<pre class="brush: cpp;">
int dirPin  = 4;
int stepperPin= 3;
int sleepPin=7;
void setup () {
pinMode (dirPin, OUTPUT);
pinMode (stepperPin, OUTPUT);
pinMode(sleepPin,OUTPUT);
}

void step(boolean dir,int steps){
digitalWrite(sleepPin,HIGH);
digitalWrite(dirPin,dir);
delay(50);
for(int i=0;i&amp;lt;steps;i++){
digitalWrite(stepperPin, HIGH);
delayMicroseconds(100);
digitalWrite(stepperPin, LOW);
delayMicroseconds(100);

}
digitalWrite(sleepPin,LOW);
}
void loop(){
step(true,15);
delay(500);
step(false,15);
delay(500);
}
</pre>
<p>The code is self explanatory, there is a simple step function which allows a direction to be input 0 for clockwise and 1 for anti-clockwise. The steps are the number of movements which the motor should take. The duration of the 1 step is determined by the delayMicroseconds in the functions which determines how long to hold the pulse high and in turning causing the motor to turn for that time period.  The main function or the loop simply calls this function once to make it turn clockwise and then anticlockwise. If this works as expected and the motor is moving the hardware step to the project is complete. We are now ready to create the front end software, the arduino would then be revisited once the front end software is complete.</p>
<p>Please note that the above code is not the final version of the code to go on the microcontroller and would be revisited.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=74&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/12/05/the-diy-surveillance-system-using-a-webcam-part-1/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/12/camera_mount-1.jpg" medium="image">
			<media:title type="html">camera_mount-1</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/12/flow_diagram2.jpg" medium="image">
			<media:title type="html">Flow_Diagram</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/12/stepper-simplified1.jpg" medium="image">
			<media:title type="html">Stepper-simplified</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript &#8211; CSS debugging using FireBug</title>
		<link>http://garagedeveloper.wordpress.com/2009/02/07/javascript-css-debugging-using-firebug/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/02/07/javascript-css-debugging-using-firebug/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 17:50:53 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[JavaScript-CSS]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=53</guid>
		<description><![CDATA[Often while working with JavaScript people place alerts (in a debugging context) throughout the code to check whether what they’re doing is correct or not. I find that pretty annoying and while I continued doing it (placing alerts) I came across Firebug introduced to be by my friend Sergey Arakelov (www.arakelov.com). Firebug is open source [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=53&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Often while working with JavaScript people place alerts (in a debugging context) throughout the code to check whether what they’re doing is correct or not. I find that pretty annoying and while I continued doing it (placing alerts) I came across Firebug introduced to be by my friend Sergey Arakelov (www.arakelov.com). Firebug is open source multi-purpose debugger and was initially intended for Firefox as a plug-in, now it supports IE and Safari as well.<span id="more-53"></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The greatest thing about Firebug is that it is browser based and if you’re using Firefox it’s just a matter of accessing the plug-in. FireBug also allows you to check you’re CSS, edit, change or disable certain lines to see the expected output. Great news for newbie CSS coders who can now practice/learn design based on hit n trial. Let’s have a look at some of these features in practice. For this tutorial I will be using Firefox version 3.05.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Tools needed:</span></p>
<p class="MsoListParagraph" style="text-indent:-18pt;margin:0 0 10pt 54pt;"><span><span><span style="font-size:small;font-family:Calibri;">1)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">FireBug plug-in can be downloaded at: </span><a href="https://addons.mozilla.org/firefox/addon/1843"><span style="font-size:small;font-family:Calibri;">https://addons.mozilla.org/firefox/addon/1843</span></a><span style="font-size:small;font-family:Calibri;"> or visit </span><a href="http://www.getfirebug.com/"><span style="font-size:small;color:#0000ff;font-family:Calibri;">www.getfirebug.com</span></a><span style="font-size:small;font-family:Calibri;"> for other ways of using the tool other than as a plug-in for Firefox.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Install the plug-in and you’re ready to go. Open Firefox with the page containing your CSS, HTML, JavaScript. </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">First let’s look at how CSS design can be viewed/improved using FireBug. The page I created looks like this:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> <span style="font-size:small;font-family:Calibri;"><a href="http://garagedeveloper.files.wordpress.com/2009/02/13.jpg"><img class="alignnone size-full wp-image-59" title="13" src="http://garagedeveloper.files.wordpress.com/2009/02/13.jpg?w=497&#038;h=279" alt="13" width="497" height="279" /></a></span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now right-click in the browser window and click “Inspect Element”, make sure FireBug is installed at this point.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><a href="http://garagedeveloper.files.wordpress.com/2009/02/2.jpg"><img class="alignnone size-full wp-image-60" title="2" src="http://garagedeveloper.files.wordpress.com/2009/02/2.jpg?w=202&#038;h=83" alt="2" width="202" height="83" /></a></span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Or as an alternative click the “Bug” image at the bottom-right corner of the browser which looks like: </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><img class="alignnone size-full wp-image-62" title="3" src="http://garagedeveloper.files.wordpress.com/2009/02/3.jpg?w=34&#038;h=29" alt="3" width="34" height="29" /></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">A window at the bottom of the browser would appear. Click the CSS tab to view/edit the CSS directly.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> <a href="http://garagedeveloper.files.wordpress.com/2009/02/4.jpg"><img class="alignnone size-full wp-image-63" title="4" src="http://garagedeveloper.files.wordpress.com/2009/02/4.jpg?w=497&#038;h=337" alt="4" width="497" height="337" /></a></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now click at each of the attributes and see how it affects the design. Double clicking the empty space also allows you to add new attributes at runtime or right click and select “new property”. I get the following output when I disable the “boxhead” attributes, observe how it is different from the previous design.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><a href="http://garagedeveloper.files.wordpress.com/2009/02/5.jpg"><img class="alignnone size-full wp-image-64" title="5" src="http://garagedeveloper.files.wordpress.com/2009/02/5.jpg?w=497&#038;h=254" alt="5" width="497" height="254" /></a></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Pretty simple and easy to use eh ?. It’s an ideal tool if you wish to learn about CSS, different properties or even test your design out.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Moving on to some more functionality, let’s see how JavaScript debugging works using FireBug. Enable JavaScript debugging by selecting the “script” tag and checking the option “support for JavaScript debugging”</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> <a href="http://garagedeveloper.files.wordpress.com/2009/02/6.jpg"><img class="alignnone size-full wp-image-65" title="6" src="http://garagedeveloper.files.wordpress.com/2009/02/6.jpg?w=497&#038;h=303" alt="6" width="497" height="303" /></a></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Within the same page I created a simple script that executes a loop as follows: </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#548dd4;font-family:&quot;">&lt;script type</span><span style="font-size:10pt;color:#666666;font-family:&quot;">=</span><span style="font-size:10pt;color:#ba2121;font-family:&quot;">&#8220;text/javascript&#8221;</span><span style="font-size:10pt;color:#666666;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:green;font-family:&quot;">function</span></strong><span style="font-size:10pt;font-family:&quot;"> test(){</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:green;font-family:&quot;">var</span></strong><span style="font-size:10pt;font-family:&quot;"> x<span style="color:#666666;">=0;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:green;font-family:&quot;">while</span></strong><span style="font-size:10pt;font-family:&quot;">(x<span style="color:#666666;">&lt;10</span>){</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">x<span style="color:#666666;">=</span>x<span style="color:#666666;">+1;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#548dd4;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#548dd4;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#548dd4;font-family:&quot;">test();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#548dd4;font-family:&quot;">&lt;/script&gt;</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Open FireBug, Select the scripts tab and find the code you wish to debug, then place the break point by clicking the line number, add a watch by clicking the watch tab on the left and adding your variable, in this case it is “x “. Refresh the Page and <span> </span>press F8 to Continue. The image below highlights these features:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> <a href="http://garagedeveloper.files.wordpress.com/2009/02/7.jpg"><img class="alignnone size-full wp-image-66" title="7" src="http://garagedeveloper.files.wordpress.com/2009/02/7.jpg?w=496&#038;h=276" alt="7" width="496" height="276" /></a></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">These features are very useful if you have lots of functions in JavaScript with multiple calls. Overall a great tool, highly recommended.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=53&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/02/07/javascript-css-debugging-using-firebug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/13.jpg" medium="image">
			<media:title type="html">13</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/2.jpg" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/3.jpg" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/4.jpg" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/5.jpg" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/6.jpg" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/02/7.jpg" medium="image">
			<media:title type="html">7</media:title>
		</media:content>
	</item>
		<item>
		<title>SAJAX-Passing Arguments to PHP &#8211; Javascript and MySQL Database</title>
		<link>http://garagedeveloper.wordpress.com/2009/01/11/sajax-passing-arguments-and-mysql-database-manipulation/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/01/11/sajax-passing-arguments-and-mysql-database-manipulation/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 02:36:08 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[PHP-AJAX]]></category>
		<category><![CDATA[AJAX and MYSQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP and AJAX argument passing]]></category>
		<category><![CDATA[SAJAX and Arguments]]></category>
		<category><![CDATA[SAJAX and Databases]]></category>
		<category><![CDATA[SAJAX and Forms]]></category>
		<category><![CDATA[SAJAX and MYSQL]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=31</guid>
		<description><![CDATA[  In the last post I presented an overview of the SAJAX library. Today I will talk about argument passing to and from the SAJAX function and the respective JavaScript function.  Then I shall make a sample HTML form and pass the values to the PHP function for addition into a MySQL database. If you are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=31&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">In the last post I presented an overview of the SAJAX library. Today I will talk about argument passing to and from the SAJAX function and the respective JavaScript function.  Then I shall make a sample HTML form and pass the values to the PHP function for addition into a MySQL database. If you are new to SAJAX and don’t know what I’m talking about I suggest you view my earlier post which can be found at: </span><a href="http://garagedeveloper.wordpress.com/2009/01/09/using-ajax-with-php/"><span style="font-size:small;font-family:Calibri;">http://garagedeveloper.wordpress.com/2009/01/09/using-ajax-with-php/</span></a></p>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span id="more-31"></span></p>
<p class="MsoNormal" style="text-align:justify;margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The code last time looked something like:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      return </span><span style="color:#dd0000;">&#8216;hello World&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_debug_mode </span><span style="color:#007700;">= </span><span style="color:#0000bb;">1</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">&lt;script&gt;</span></p>
<p></span><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">X_worker(callback);</p>
<p>Function callback(retArg){</p>
<p>Alert(retArg);}</span></p>
<p><span style="color:#0000ff;">&lt;/script&gt;</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">Make sure you have the SAJAX libraries.</p>
<p class="MsoNormal" style="text-align:justify;margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">Let’s make the worker function do something interesting then a mere hello world. I will edit the worker function so now it takes two strings concatenates them and returns the result back to the JavaScript Function.  </span></span></p>
<p class="MsoNormal" style="text-align:justify;margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">So I change the worker function and now it looks like this:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;"> </span><span style="color:#007700;">function </span><span style="color:#0000bb;">worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$arg1</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$arg2</span></span><span style="font-family:Courier New;"><span style="color:#007700;">)<br />
  {<br />
      </span><span style="color:#0000bb;">$cat </span><span style="color:#007700;">= </span><span style="color:#0000bb;">$arg1 </span><span style="color:#007700;">. </span><span style="color:#dd0000;">&#8216; &#8217; </span><span style="color:#007700;">. </span><span style="color:#0000bb;">$arg2</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
      <br />
      return </span><span style="color:#0000bb;">$cat</span></span><span style="color:#007700;"><span style="font-family:Courier New;">;<br />
  }</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Notice however I don’t change the “export” call arguments.  So the code till this point looks like: </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$arg1</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$arg2</span></span><span style="font-family:Courier New;"><span style="color:#007700;">)<br />
  {<br />
      </span><span style="color:#0000bb;">$cat </span><span style="color:#007700;">= </span><span style="color:#0000bb;">$arg1 </span><span style="color:#007700;">. </span><span style="color:#dd0000;">&#8216; &#8217; </span><span style="color:#007700;">. </span><span style="color:#0000bb;">$arg2</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
      <br />
      return </span><span style="color:#0000bb;">$cat</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_debug_mode </span><span style="color:#007700;">= </span><span style="color:#0000bb;">1</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">&lt;script&gt;</span></p>
<p></span><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">X_worker(callback);</p>
<p>Function callback(retArg){</p>
<p>Alert(retArg);}<br />
</span><br />
<span style="color:#0000ff;">&lt;/script&gt;</span></span><br />
</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now I change the respective JavaScript function <strong>Call</strong> to look like this:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#0000ff;"><span style="font-family:Courier New;"><span style="color:#0000bb;">x_worker</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8216;something&#8217;</span><span style="color:#007700;">, </span><span style="color:#dd0000;">&#8216;intresting&#8217;</span><span style="color:#007700;">, </span><span style="color:#0000bb;">cb</span><span style="color:#007700;">)</span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">You can pass any number of arguments at the start and the last argument always is the <strong>Call-back </strong>function name. So the code looks like:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$arg1</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$arg2</span></span><span style="font-family:Courier New;"><span style="color:#007700;">)<br />
  {<br />
      </span><span style="color:#0000bb;">$cat </span><span style="color:#007700;">= </span><span style="color:#0000bb;">$arg1 </span><span style="color:#007700;">. </span><span style="color:#dd0000;">&#8216; &#8217; </span><span style="color:#007700;">. </span><span style="color:#0000bb;">$arg2</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
      <br />
      return </span><span style="color:#0000bb;">$cat</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_debug_mode </span><span style="color:#007700;">= </span><span style="color:#0000bb;">1</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">&lt;script&gt;</span></p>
<p></span><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">x_worker(&#8216;something&#8217;,'intresting&#8217;,callback) </p>
<p><span style="color:#007700;">function</span> callback(retArg){</p>
<p>Alert(retArg);}</span></p>
<p><span style="color:#0000ff;">&lt;/script&gt;</span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><br />
</span></span></span><span style="font-size:small;"><span style="font-family:Calibri;">When the retArg alerts you get something like: “something interesting”. Easy wasn’t it </span><span style="font-family:Wingdings;">J</span><span style="font-family:Calibri;"> ?. Similarly you can pass any number of arguments this way to your PHP function be it arrays, objects, and strings. Just make sure you don’t echo something out in the PHP function or have your include libraries before the SAJAX stuff. </span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now let’s look at how you can get values in your JavaScript function in a similar way. For this I shall declare an array in the PHP function and make it return the array to the JavaScript. So Now the PHP function looks like this: </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;"> </span><span style="color:#007700;">function </span><span style="color:#0000bb;">worker</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      </span><span style="color:#0000bb;">$arr </span><span style="color:#007700;">= array(</span><span style="color:#dd0000;">&#8220;foo&#8221; </span><span style="color:#007700;">=&gt; </span><span style="color:#dd0000;">&#8220;bar&#8221;</span><span style="color:#007700;">, </span><span style="color:#dd0000;">&#8220;Max&#8221; </span><span style="color:#007700;">=&gt; </span><span style="color:#dd0000;">&#8220;Sajax&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
      <br />
      return </span><span style="color:#0000bb;">$arr</span></span><span style="color:#007700;"><span style="font-family:Courier New;">;<br />
  }</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">$arr is an array with bar at location “foo” and sajax at location “Max”. In the respective JavaScript function I output the values like :  </span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;">alert</span><span style="color:#007700;">(</span><span style="color:#0000bb;">retArg</span><span style="color:#007700;">[</span><span style="color:#dd0000;">"foo"</span><span style="color:#007700;">]);</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">which outputs bar where retArg is the arg from the call-back function. The code is now:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      </span><span style="color:#0000bb;">$arr </span><span style="color:#007700;">= array(</span><span style="color:#dd0000;">&#8220;foo&#8221; </span><span style="color:#007700;">=&gt; </span><span style="color:#dd0000;">&#8220;bar&#8221;</span><span style="color:#007700;">, </span><span style="color:#dd0000;">&#8220;Max&#8221; </span><span style="color:#007700;">=&gt; </span><span style="color:#dd0000;">&#8220;Sajax&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
      <br />
      return </span><span style="color:#0000bb;">$arr</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_debug_mode </span><span style="color:#007700;">= </span><span style="color:#0000bb;">1</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="color:#0000bb;"><span style="font-family:Courier New;">?&gt;</span><br />
</span><br />
</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#0000ff;"><span style="font-family:Courier New;">&lt;script&gt;</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
</span><span style="color:#0000bb;">?&gt;</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;">x_worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">callback</span><span style="color:#007700;">);</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#007700;">Function </span><span style="color:#0000bb;">callback</span><span style="color:#007700;">(</span><span style="color:#0000bb;">retArg</span></span><span style="font-family:Courier New;"><span style="color:#007700;">)<br />
  {<br />
      </span><span style="color:#0000bb;">Alert</span><span style="color:#007700;">(</span><span style="color:#0000bb;">retArg</span><span style="color:#007700;">[</span><span style="color:#0000bb;">“foo”</span></span><span style="color:#007700;"><span style="font-family:Courier New;">]);<br />
  }</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#0000ff;"><span style="font-family:Courier New;">&lt;/script&gt;</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Okay now that you’ve got grips with all this (I hope) let’s move to creating a simple html form getting data from it and inserting it in a database which is mysql in this case. Ok so let’s begin. First I edit the worker function so that I perform a simple insert MYSQL query. Ill assume you have already setup the connection with the database, I place mine in a separate file which in this case it is ‘database.php’. The worker function now becomes: </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;"> <span style="color:#007700;">function </span><span style="color:#0000bb;">worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$name</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$dob</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$address</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$pnum</span><span style="color:#007700;">)<br />
  {<br />
      </span><span style="color:#0000bb;"><a title="Open the PHP manual for mysql_query" href="http://www.php.net/mysql_query" target="_blank">mysql_query</a></span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;INSERT INTO tbl_name (name,dob,address,pnum) </span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="color:#dd0000;">      VALUES($name,$dob,$address,$pnum)&#8221;</span><span style="color:#007700;">;<br />
      <br />
      return </span><span style="color:#0000bb;">0</span><span style="color:#007700;">;<br />
  }<br />
</span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">I create a simple HTML form which holds some basic details and looks likes this: </span></p>
<p><strong></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-weight:bold;color:#008000;"><span style="font-weight:bold;color:#008000;">&lt;meta</span> <span style="color:#7d9029;">http-equiv=</span><span style="color:#ba2121;">&#8220;Content-Type&#8221;</span> <span style="color:#7d9029;">content=</span><span style="color:#ba2121;">&#8220;text/html; charset=utf-8&#8243;</span> <span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;title&gt;</span>Untitled Document<span style="font-weight:bold;color:#008000;">&lt;/title&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/head&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;form</span> <span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;frmDetails&#8221;</span><span style="font-weight:bold;color:#008000;">&gt;</span></p>
<p>Name:<span style="font-weight:bold;color:#008000;">&lt;input</span> <span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span> <span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;nam&#8221;</span> <span style="font-weight:bold;color:#008000;">/&gt;</span> <span style="font-weight:bold;color:#008000;">&lt;br</span> <span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p>DOB:<span style="font-weight:bold;color:#008000;">&lt;input</span> <span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span> <span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;DOB&#8221;</span> <span style="font-weight:bold;color:#008000;">/&gt;&lt;br</span> <span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p>Address:<span style="font-weight:bold;color:#008000;">&lt;input</span> <span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span> <span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;Address&#8221;</span> <span style="font-weight:bold;color:#008000;">/&gt;&lt;br</span> <span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p>Phone Number:<span style="font-weight:bold;color:#008000;">&lt;input</span> <span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span> <span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;Pnum&#8221;</span> <span style="font-weight:bold;color:#008000;">/&gt;&lt;br</span> <span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;input</span> <span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;submit&#8221;</span> <span style="color:#7d9029;">value=</span><span style="color:#ba2121;">&#8220;Submit&#8221;</span> <span style="color:#7d9029;">onclick=</span><span style="color:#ba2121;">&#8220;run()&#8221;</span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/form&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;body&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/body&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/html&gt;</span></p>
<p></span><span style="font-size:small;font-family:Calibri;">Notice on the onClick event I’m calling a run() function. This is the function which takes all the values from the form when the submit button is clicked and calls our JavaScript worker function so the run function is:</span></p>
<p>  <span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#007700;">function </span><span style="color:#0000bb;">run</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      </span><span style="color:#0000bb;">x_worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">frmDetails</span><span style="color:#007700;">.</span><span style="color:#0000bb;">nam</span><span style="color:#007700;">.</span><span style="color:#0000bb;">value</span><span style="color:#007700;">, </span><span style="color:#0000bb;">frmDetails </span><span style="color:#007700;">. </span><span style="color:#0000bb;">DOB </span><span style="color:#007700;">. </span><span style="color:#0000bb;">value</span><span style="color:#007700;">, </span><span style="color:#0000bb;">frmDetails </span><span style="color:#007700;">. </span><span style="color:#0000bb;">Address </span><span style="color:#007700;">. </span><span style="color:#0000bb;">value</span><span style="color:#007700;">, </span></span></span></span></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#0000bb;">      frmDetails </span><span style="color:#007700;">. </span><span style="color:#0000bb;">Pnum </span><span style="color:#007700;">. </span><span style="color:#0000bb;">value</span><span style="color:#007700;">, </span><span style="color:#0000bb;">callback</span></span><span style="color:#007700;"><span style="font-family:Courier New;">);<br />
  }</span></span></span></span></p>
<p> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">I get the values from the form and pass them to the worker function.  In the PHP worker function I return a 0 which can act as an identifier if everything went alright or not. The entire code is as follows:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="color:#000000;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span><span style="color:#007700;">);<br />
  <br />
  include(</span><span style="color:#0000bb;">‘ database </span><span style="color:#007700;">. </span><span style="color:#0000bb;">php’</span><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$name</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$dob</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$address</span><span style="color:#007700;">, </span><span style="color:#0000bb;">$pnum</span><span style="color:#007700;">)<br />
  {<br />
      </span><span style="color:#0000bb;"><a title="Open the PHP manual for mysql_query" href="http://www.php.net/mysql_query" target="_blank"><strong>mysql_query</strong></a></span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;INSERT INTO tbl_name (name,dob,address,pnum) VALUES($name,$dob,$address,$pnum)&#8221;</span><span style="color:#007700;">;<br />
      <br />
      return </span><span style="color:#0000bb;">0</span><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#ff8000;">//$sajax_debug_mode=1;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span><span style="color:#007700;">();<br />
</span><span style="color:#0000bb;">?&gt;</span></span></span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="color:#bc7a00;">&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;html</span><span style="color:#000000;"> </span><span style="color:#7d9029;">xmlns=</span><span style="color:#ba2121;">&#8220;http://www.w3.org/1999/xhtml&#8221;</span><span style="font-weight:bold;color:#008000;">&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;head&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;script&gt;</span></span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><br />
</span></span></span></span></span><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="color:#000000;"><span style="color:#0000bb;">&lt;?php<br />
  sajax_show_javascript</span><span style="color:#007700;">();<br />
</span><span style="color:#0000bb;">?&gt;</span></span></span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="font-weight:bold;color:#008000;">function</span><span style="color:#000000;"> <span style="color:#3366ff;">callback(retArg)</span></p>
<p><span style="color:#3366ff;">{</span></span></span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="color:#3366ff;">alert(retArg);</span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="color:#000000;"><span style="color:#3366ff;">}</span><br />
</span></span></span></span></span></span></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#007700;">function </span><span style="color:#3366ff;">run</span></span><span style="font-family:Courier New;"><span style="color:#007700;"><span style="color:#3366ff;">()<br />
</span><span style="color:#3366ff;">{</span><br />
</span><span style="color:#3366ff;">x_worker(frmDetails.nam.value,frmDetails.DOB.value,</span></span></span></span></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#3366ff;">frmDetails.Address.value, </span></span></span></span></p>
<p><span style="font-size:small;"></span><span style="font-size:small;"><span style="font-family:Calibri;"><span style="font-family:Courier New;"><span style="color:#3366ff;">frmDetails.Pnum.value,callback</span></span><span style="color:#007700;"><span style="font-family:Courier New;"><span style="color:#3366ff;">);</span><br />
<span style="color:#3366ff;">}</span></span></span></span></span><span style="color:#3366ff;"> </span></p>
<p> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;"><span style="font-weight:bold;color:#008000;">&lt;/script&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;meta</span><span style="color:#000000;"> </span><span style="color:#7d9029;">http-equiv=</span><span style="color:#ba2121;">&#8220;Content-Type&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">content=</span><span style="color:#ba2121;">&#8220;text/html; charset=utf-8&#8243;</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;title&gt;</span><span style="color:#000000;">Untitled Document</span><span style="font-weight:bold;color:#008000;">&lt;/title&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/head&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;form</span><span style="color:#000000;"> </span><span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;frmDetails&#8221;</span><span style="font-weight:bold;color:#008000;">&gt;</span></p>
<p><span style="color:#000000;">Name:</span><span style="font-weight:bold;color:#008000;">&lt;input</span><span style="color:#000000;"> </span><span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;nam&#8221;</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">&lt;br</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="color:#000000;">DOB:</span><span style="font-weight:bold;color:#008000;">&lt;input</span><span style="color:#000000;"> </span><span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;DOB&#8221;</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;&lt;br</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="color:#000000;">Address:</span><span style="font-weight:bold;color:#008000;">&lt;input</span><span style="color:#000000;"> </span><span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;Address&#8221;</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;&lt;br</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="color:#000000;">Phone Number:</span><span style="font-weight:bold;color:#008000;">&lt;input</span><span style="color:#000000;"> </span><span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;text&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">name=</span><span style="color:#ba2121;">&#8220;Pnum&#8221;</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;&lt;br</span><span style="color:#000000;"> </span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;input</span><span style="color:#000000;"> </span><span style="color:#7d9029;">type=</span><span style="color:#ba2121;">&#8220;submit&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">value=</span><span style="color:#ba2121;">&#8220;Submit&#8221;</span><span style="color:#000000;"> </span><span style="color:#7d9029;">onclick=</span><span style="color:#ba2121;">&#8220;run()&#8221;</span><span style="font-weight:bold;color:#008000;">/&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/form&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;body&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/body&gt;</span></p>
<p><span style="font-weight:bold;color:#008000;">&lt;/html&gt;</span><br />
</span></span></span></span></span> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">Hope this helps and clears out some confusion on the use of SAJAX </span><span style="font-family:Wingdings;">J</span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=31&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/01/11/sajax-passing-arguments-and-mysql-database-manipulation/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>
	</item>
		<item>
		<title>Using AJAX With PHP &#8211; The SAJAX Way</title>
		<link>http://garagedeveloper.wordpress.com/2009/01/09/using-ajax-with-php/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/01/09/using-ajax-with-php/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 05:48:11 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[PHP-AJAX]]></category>
		<category><![CDATA[AJAX using PHP]]></category>
		<category><![CDATA[PHP And Sajax]]></category>
		<category><![CDATA[SAJAX]]></category>
		<category><![CDATA[SAJAX Examples]]></category>
		<category><![CDATA[Sajax Hello World]]></category>
		<category><![CDATA[SAJAX Problems]]></category>
		<category><![CDATA[Using AJAX with PHP]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=21</guid>
		<description><![CDATA[  Right so the objective is to use PHP with AJAX to achieve what is normally known as “refresh less browsing”. When I started off with my work I had to deal with quiet a lot of forms which posted variables to  a PHP page and then I could use them either by query string [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=21&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Right so the objective is to use PHP with AJAX to achieve what is normally known as “refresh less browsing”. When I started off with my work I had to deal with quiet a lot of forms which posted variables to  a PHP page and then I could use them either by query string or whatever method to display them. The only problem with this was that the page had to be refreshed. I had a vague idea about AJAX but never really got into using it until I really got fed up of page refreshes, so if you share the same enthusiasm (slightly) this might prove helpful.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><span id="more-21"></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Besides the story above AJAX stands for Asynchronous JavaScript and XML. The objective of AJAX is to allow asynchronous transfer of data from the server to the client and vice versa without interfering with any of the stuff on the main page (page refreshes) and since JavaScript is executed on the client end and PHP code is executed on the server end (duh) we need a way to do that. How AJAX actually achieves that we’ll leave that discussion for another time. Now i have been searching for a library or something magical that makes my life easier. That’s when i came across SAJAX an open source library which does that something magical.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">So what do you need:</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-18pt;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;">1)</span><span style="font:7pt &quot;">      </span><span style="font-size:small;font-family:Calibri;">PHP ( since we will be using SAJAX with PHP) whatever version I used 5 i don’t know if SAJAX works with other versions or not</span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-18pt;margin:0 0 10pt 36pt;"><span style="font-size:small;font-family:Calibri;">2)</span><span style="font:7pt &quot;">      </span><span style="font-size:small;font-family:Calibri;">SAJAX library can be found at : </span><a href="http://www.modernmethod.com/sajax/download.phtml"><span style="font-size:small;font-family:Calibri;">http://www.modernmethod.com/sajax/download.phtml</span></a><span style="font-size:small;font-family:Calibri;"> download the zip file and extract it to wherever you need it</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now within the SAJAX there would be a number of folders. ASP, Coldfusion and others(Probably support for other platforms, you could’ve guessed that couldn’t you ! ).  So there is another folder PHP open it and get the “SAJAX.php” file from there and paste it in the project or folder or wherever you wish to use it. Notice there are a few examples there as well if you can get a grip of it from it i guess this is the end of the line for you then <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  but if not continue reading.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Ok so now we have the library so lets begin. At the top of your PHP page include:</span></p>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="color:#007700;"><span style="font-family:Courier New;">);<br />
</span></span><span style="color:#0000bb;"><span style="font-family:Courier New;">?&gt;</span><br />
</span><br />
</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Can be a include as well but a personal choice. Now the objective:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Send data from client to server &#8211; &gt; Process it &#8211; &gt; Return it to Client which is</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">JavaScript -&gt; PHP -&gt; JavaScript</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">So first we define a function in PHP which would be the worker or which would do something when invoked by the client, which means I’m effectively entertaining the middle part of the chain which I just mentioned above. Once you get the hold of it you can start off from anywhere. So I declare a function like: </span></p>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  Function </span><span style="color:#0000bb;">worker</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      Return </span><span style="color:#0000bb;">‘hello world’</span></span><span style="color:#007700;"><span style="font-family:Courier New;">;<br />
  }<br />
</span></span><span style="color:#0000bb;"><span style="font-family:Courier New;">?&gt;</span></span></span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="color:#0000bb;"><br />
</span></span></span></span><span style="font-size:small;font-family:Calibri;">Right so the function will simply worker function will simply return a hello world. Now we add some SAJAX stuff which actually export this function to JavaScript and make everything happen.  After my function I stick in these lines: </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#ff0000;">$sajax_request_type = &#8221;GET&#8221;;</p>
<p>sajax_init();</p>
<p>$sajax_debug_mode=1;</p>
<p>sajax_export(&#8220;worker&#8221;);</p>
<p>sajax_handle_client_request();</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"></span></span><span style="font-size:small;font-family:Calibri;">Now lets go through each of these lines. Firstly the request type, it works the same way as in normal forms, the GET method appends values to the URL and since the URL can only handle a limited number of parameters there is a possibility it might get truncated so its only used if the amount of parameters to be passed are less, simililary the fields such as passwords etc will be displayed if passed using the GET method.  This can also be a “POST” request which would require changing the above to “POST” which appends all the values to the body of the HTTP request. Too much detail?. Anyway the second line sajax_init() initializes the library variables etc. The third line is a not so fancy debugger which outputs what happens behinds the curtains in the form of alert boxes set it to “0”if you don’t want to use it and set it to “1” if you want to use it or better just remove the line if you don’t care. The fourth line is and export call which tells the library this is the function we wish to export, export where? To the JavaScript so that we make use of it, how? We shall know it soon.</span></p>
<p class="MsoNormal" style="text-align:justify;margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Notice however one thing no matter what type of function you have or whatever it takes as arguments you just have to put its name in the export and nothing else remember NOTHING ELSE JUST THE NAME. We shall see how we deal with arguments later on. The last line simply tells the library to get ready to handle requests from the client its like an automatic poller thing which checks for requests so now the overall code looks like this: </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      return </span><span style="color:#dd0000;">&#8216;hello World&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_debug_mode </span><span style="color:#007700;">= </span><span style="color:#0000bb;">1</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
</span><span style="color:#0000bb;">?&gt;</span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"></span></span></span></span><span style="font-size:small;font-family:Calibri;">Now we call this function from our JavaScript, before that we need to stick a small line into our JavaScript code which is:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000ff;">&lt;script&gt;</span></p>
<p></span><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000ff;">&lt;/script&gt;</span></span></span></span></span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"></span></span><span style="font-size:small;font-family:Calibri;">This is something which just be done to make the function usable and i have nothing to do with it. Now lets call our JavaScript function which is done by:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000ff;">&lt;script&gt;</span></p>
<p></span><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">X_worker(callback);</p>
<p>Function callback(retArg)</p>
<p></span><span style="color:#0000ff;">{</p>
<p>Alert(retArg);<br />
</span><br />
<span style="color:#3366ff;"><span style="color:#0000ff;">}</span><br />
</span><br />
<span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000ff;">&lt;/script&gt;</span><br />
</span></span></span></span></span></span></span></span><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Ok so lets see what’s going on we had a function in PHP called worker no in order to call it from JavaScript we must append and “x_” to the name of the function we “exported” so it becomes x_worker if the export function was “test” then we call it using “x_test”.  Within the function though there is no argument in the PHP function though in JavaScript I pass a call-back argument. This in fact is the function which would be called once the worker function is done doing its job so in this case the name is call-back and the returned argument from the PHP function is “hello world” so retArg alerts “hello world”</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Ok some things to mention and try out:</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-18pt;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;">1)</span><span style="font:7pt &quot;">      </span><span style="font-size:small;font-family:Calibri;">Do not try to echo or use print statements within the PHP function if you try to do that, it will append the results with the return argument and give you an error “Cannot Eval” in the debugger.</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;">2)</span><span style="font:7pt &quot;">      </span><span style="font-size:small;font-family:Calibri;">When using the statements : </span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"><span style="color:#ff0000;">$sajax_request_type = &#8221;GET&#8221;;</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"><span style="color:#ff0000;">sajax_init();</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"><span style="color:#ff0000;">$sajax_debug_mode=1;</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"><span style="color:#ff0000;">sajax_export(&#8220;worker&#8221;);</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"><span style="color:#ff0000;">sajax_handle_client_request();</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"></span><span style="font-size:small;font-family:Calibri;"><span style="font-size:small;font-family:Calibri;">Make sure you place them before any of your other “includes” because it would append them to the results and what you would see in your debugger is a</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"><span style="font-size:small;font-family:Calibri;"><span style="font-size:small;font-family:Calibri;">full HTML alert.</span><span style="font-size:small;font-family:Calibri;">The final code looks like this:</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;text-align:left;margin:0 0 0 36pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000bb;">&lt;?php<br />
  </span><span style="color:#007700;">require(</span><span style="color:#dd0000;">&#8216;Sajax.php&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  function </span><span style="color:#0000bb;">worker</span></span><span style="font-family:Courier New;"><span style="color:#007700;">()<br />
  {<br />
      return </span><span style="color:#dd0000;">&#8216;hello World&#8217;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  }<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_request_type </span><span style="color:#007700;">= </span><span style="color:#dd0000;">&#8220;GET&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_init</span></span><span style="font-family:Courier New;"><span style="color:#007700;">();<br />
  <br />
  </span><span style="color:#0000bb;">$sajax_debug_mode </span><span style="color:#007700;">= </span><span style="color:#0000bb;">1</span></span><span style="font-family:Courier New;"><span style="color:#007700;">;<br />
  <br />
  </span><span style="color:#0000bb;">sajax_export</span><span style="color:#007700;">(</span><span style="color:#dd0000;">&#8220;worker&#8221;</span></span><span style="font-family:Courier New;"><span style="color:#007700;">);<br />
  <br />
  </span><span style="color:#0000bb;">sajax_handle_client_request</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">&lt;script&gt;<br />
</span><br />
</span><span style="color:#0000bb;"><span style="font-family:Courier New;">&lt;?php<br />
  sajax_show_javascript</span></span><span style="color:#007700;"><span style="font-family:Courier New;">();<br />
</span></span><span style="font-family:Courier New;"><span style="color:#0000bb;">?&gt;<br />
</span><br />
<span style="color:#0000ff;">X_worker(callback);</p>
<p>Function callback(retArg){</p>
<p>Alert(retArg);}</p>
<p></span><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><span style="font-family:Courier New;"><span style="color:#0000ff;">&lt;/script&gt;</span><br />
</span></span></span></span></span></span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span style="color:#000000;"><br />
</span></span></span><span style="font-size:small;font-family:Calibri;">The next post will cover passing arguments from be it arrays, objects etc using the SAJAX. Feel free to post any questions and I will try to get back to you with answers.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=21&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/01/09/using-ajax-with-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>
	</item>
		<item>
		<title>Splash Screen &#8211; Design</title>
		<link>http://garagedeveloper.wordpress.com/2009/01/08/splash-screen-design/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/01/08/splash-screen-design/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 22:12:24 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[photoshop]]></category>
		<category><![CDATA[photoshop design]]></category>
		<category><![CDATA[removing photoshop background]]></category>
		<category><![CDATA[splash screen for wordpress]]></category>
		<category><![CDATA[wordpress banner]]></category>
		<category><![CDATA[wordpress splash screen]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=11</guid>
		<description><![CDATA[So I got a wordpress theme and decided to make a splash screen which was at the top with one of my own because the orginal one, though was amazing but I couldnt actually understand what it was. So I opened photoshop entered the dimensions: 761&#215;151 px how do i know that ? well in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=11&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I got a wordpress theme and decided to make a splash screen which was at the top with one of my own because the orginal one, though was amazing but I couldnt actually understand what it was. So I opened photoshop entered the dimensions: 761&#215;151 px how do i know that ? well in the themes section in the wordpress admin clicking on the custom image header shows these dimensions. Ok for the splash screen I had something in mind to make a garage with some grass and a guy with a shovel, something like a typical garage environment at the same time I wanted it to be all black white and shades of gray.Initially I made an ellipse assigned it the color grey and moved it down so one part of it stayed up the rest of it down, which doesnt get included so no harm done.</p>
<p><span id="more-11"></span></p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/01/ellipse.jpg"><img class="size-full wp-image-14 alignnone" title="ellipse" src="http://garagedeveloper.files.wordpress.com/2009/01/ellipse.jpg?w=496&#038;h=255" alt="Splash Screen-Ground" width="496" height="255" /></a></p>
<p> The next step was to add grass. I looked around for a while searching google for some grass images but then this heart shape in photoshop kept bothering me so I clicked it and voila i see lots of shapes. Scrolling through them I saw grass. Made a layer with grass and copied them by clicking &#8216;alt&#8217; and dragging them  all around the ground area. There are alot of custom shapes availible, I used grass 2 there was others aswell but just a personal choice.</p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/01/grass.jpg"><img class="alignnone size-full wp-image-15" title="Grass" src="http://garagedeveloper.files.wordpress.com/2009/01/grass.jpg?w=497&#038;h=282" alt="Grass" width="497" height="282" /></a></p>
<p>Now for the garage. I grabbed the garage image from <a href="http://www.firstdaycottage.com/images/GarageSketch.jpg">http://www.firstdaycottage.com/images/GarageSketch.jpg</a>. Now to remove its background so i could place it on the ground area I opened this image used the magic wand tool and selected the white area. Then right clicked and selected the &#8220;Select Inverse&#8221; option which gives you the inverse, the not selected area which is the garage and there you have it.</p>
<p><a href="http://garagedeveloper.files.wordpress.com/2009/01/removing-background.jpg"><img class="alignnone size-full wp-image-16" title="removing-background" src="http://garagedeveloper.files.wordpress.com/2009/01/removing-background.jpg?w=497&#038;h=282" alt="removing-background" width="497" height="282" /></a></p>
<p> The cycle , shovels even the man digging his own grave <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  is from photoshop custom shapes, thats pretty much there is to the splashscreen/banner/ watever u wanna call it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=11&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/01/08/splash-screen-design/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/01/ellipse.jpg" medium="image">
			<media:title type="html">ellipse</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/01/grass.jpg" medium="image">
			<media:title type="html">Grass</media:title>
		</media:content>

		<media:content url="http://garagedeveloper.files.wordpress.com/2009/01/removing-background.jpg" medium="image">
			<media:title type="html">removing-background</media:title>
		</media:content>
	</item>
		<item>
		<title>Yet Another Dev Blog?</title>
		<link>http://garagedeveloper.wordpress.com/2009/01/08/yet-another-dev-blog/</link>
		<comments>http://garagedeveloper.wordpress.com/2009/01/08/yet-another-dev-blog/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 19:56:17 +0000</pubDate>
		<dc:creator>garagedeveloper</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://garagedeveloper.wordpress.com/?p=3</guid>
		<description><![CDATA[Unfortunately yes!&#8230;. Ive grabbed lots of freebies thanks to blogs, and now I guess is the time to return something back to the community, so ill put up stuff that I learn and develop along the way,  hope you learn n enjoy the same way I did .<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=3&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Unfortunately yes!&#8230;. Ive grabbed lots of freebies thanks to blogs, and now I guess is the time to return something back to the community, so ill put up stuff that I learn and develop along the way,  hope you learn n enjoy the same way I did <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/garagedeveloper.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/garagedeveloper.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/garagedeveloper.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/garagedeveloper.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/garagedeveloper.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/garagedeveloper.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/garagedeveloper.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/garagedeveloper.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=garagedeveloper.wordpress.com&amp;blog=6100845&amp;post=3&amp;subd=garagedeveloper&amp;ref=&amp;feed=1" width="1" height="1" /><div class="sharedaddy sharedaddy-dark"></div>]]></content:encoded>
			<wfw:commentRss>http://garagedeveloper.wordpress.com/2009/01/08/yet-another-dev-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a607dd49a0116e3ba869a66d6fd1ba0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">garagedeveloper</media:title>
		</media:content>
	</item>
	</channel>
</rss>
