<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dave PC Guy &#187; php</title>
	<atom:link href="http://www.davepcguy.com/archive/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davepcguy.com</link>
	<description>Computers and Technology</description>
	<lastBuildDate>Fri, 08 Apr 2011 15:01:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>PHP tricks: substr()</title>
		<link>http://www.davepcguy.com/archive/php-tricks-substr/</link>
		<comments>http://www.davepcguy.com/archive/php-tricks-substr/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 20:16:39 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[php tricks]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1198</guid>
		<description><![CDATA[I&#8217;ve decided to start a new section on DavePCGuy that deals entirely with PHP tips &#38; tricks. What&#8217;s great about that is that I show you some of the lesser known/used PHP functions, PHP uses in new creative ways. First up is substr(), a simple yet rarely used function that cuts up your string. You]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=function,php,php+tricks&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve decided to start a new section on DavePCGuy that deals entirely with PHP tips &amp; tricks. What&#8217;s great about that is that I show you some of the lesser known/used PHP functions, PHP uses in new creative ways.</p>
<p>First up is<a title="substr php manual" href="http://php.net/manual/en/function.substr.php"> <strong>substr()</strong></a>, a simple yet rarely used function that cuts up your string. You tell it where to cut, and the function cuts. Now, you&#8217;ll be thinking, why use this?</p>
<p>Let me fist show you how it works.<br />
<span id="more-1198"></span><br />
<br />
The function has several different arguments that can be used, here is an overview of the three I use:</p>
<pre class="brush: php; title: ;">
substr($string, stringstart, stringend);
</pre>
<p>The first argument is the string (it can be added between quotes &#8221; &#8221; or as a $variable). Next is where the cut should start. If you want to start from the beginning of the string put a big fat &#8220;0&#8243; there. Next is where the cut should end. By using <a title="strlen php manual" href="http://php.net/manual/en/function.strlen.php"><strong>strlen()</strong></a> you can find the number of characters in the string so if you want to cut the first few letter and leave the rest, use this function to find out where the &#8220;string end&#8221; is.</p>
<p><strong>Example:</strong></p>
<pre class="brush: php; title: ;">
$websiteurl= &quot;http://bit.ly/GoEVa&quot;;

$stringend = $strlen($websiteurl);

$endletters = substr($websiteurl, 14, $stringend);

echo $endletters;
</pre>
<p>This will output, or echo out, the last few letters of the website url &#8220;GoEVa&#8221;. As you can see, this is one of the uses. I, for example, used this on a previous project to store the bit.ly shortened versions of a <a title="adding URLs to mysql database" href="http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/">website URL for twitter</a> use before I refined the script.</p>
<p><strong>USES:</strong></p>
<p>I have a few uses, one of them, as previously mentioned, was adding shortened url&#8217;s to a database. Next one is a timestamp. Using the TIMESTAMP datatype in MYSQL, and the default value &#8220;CURRENT_TIMESTAMP&#8221;, you will always get a value in this format: YYYY-MM-DD HH-mm-ss which is way too lengthy to use anywhere. To shorten it effectively, use the <strong>substr()</strong> function:</p>
<pre class="brush: php; title: ;">
$columndata = &quot;YYYY-MM-DD hh-mm-ss&quot;;

$date = substr($columndata, 0, 10);

echo $date
</pre>
<p>This will echo out only the date in the same format. It will show up this way: &#8220;2010-04-15&#8243; without the quotes. You can, of course, use the date() function if you want to but this is a really quick way.</p>
<p>There are other uses, for example if you ask for a twitter username and someone puts in the whole URL:</p>
<pre class="brush: php; title: ;">
$url = &quot;http://twitter.com/wajanusdesigns&quot;;

$strlength = strlen($url);

$finalurl=substr($url, 19, $strlength);

$finalurl;
</pre>
<p>How about a really strange password security? Make a minimum of, let&#8217;s say 10 characters for password. Look:</p>
<pre class="brush: php; title: ;">
$pass = $_POST['password'];

$strlength = strlen($pass);

$string = substr($pass, 5, $strlength);

$password = sha1($string);
</pre>
<p>And put it in your database! Who would have expected THAT?</p>
<p>To get around the &#8220;strlen()&#8221; function use, use negative numbers if you want the last few digits:</p>
<pre class="brush: php; title: ;">
$string = &quot;Hello there&quot;;

$string = substr($string, -5);

echo $string;
</pre>
<p>The final $string would be &#8220;there&#8221; instead of the whole thing.</p>
<p>As you can see there are many different creative uses for <strong>substr()</strong> function. I&#8217;m sure you can come up with more and better ones!</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;title=PHP%20tricks%3A%20substr%28%29&amp;bodytext=I%27ve%20decided%20to%20start%20a%20new%20section%20on%20DavePCGuy%20that%20deals%20entirely%20with%20PHP%20tips%20%26amp%3B%20tricks.%20What%27s%20great%20about%20that%20is%20that%20I%20show%20you%20some%20of%20the%20lesser%20known%2Fused%20PHP%20functions%2C%20PHP%20uses%20in%20new%20creative%20ways.%0D%0A%0D%0AFirst%20up%20is%20substr%28%29%2C%20a%20simple%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;title=PHP%20tricks%3A%20substr%28%29&amp;notes=I%27ve%20decided%20to%20start%20a%20new%20section%20on%20DavePCGuy%20that%20deals%20entirely%20with%20PHP%20tips%20%26amp%3B%20tricks.%20What%27s%20great%20about%20that%20is%20that%20I%20show%20you%20some%20of%20the%20lesser%20known%2Fused%20PHP%20functions%2C%20PHP%20uses%20in%20new%20creative%20ways.%0D%0A%0D%0AFirst%20up%20is%20substr%28%29%2C%20a%20simple%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;t=PHP%20tricks%3A%20substr%28%29" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;title=PHP%20tricks%3A%20substr%28%29&amp;annotation=I%27ve%20decided%20to%20start%20a%20new%20section%20on%20DavePCGuy%20that%20deals%20entirely%20with%20PHP%20tips%20%26amp%3B%20tricks.%20What%27s%20great%20about%20that%20is%20that%20I%20show%20you%20some%20of%20the%20lesser%20known%2Fused%20PHP%20functions%2C%20PHP%20uses%20in%20new%20creative%20ways.%0D%0A%0D%0AFirst%20up%20is%20substr%28%29%2C%20a%20simple%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;title=PHP%20tricks%3A%20substr%28%29&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=I%27ve%20decided%20to%20start%20a%20new%20section%20on%20DavePCGuy%20that%20deals%20entirely%20with%20PHP%20tips%20%26amp%3B%20tricks.%20What%27s%20great%20about%20that%20is%20that%20I%20show%20you%20some%20of%20the%20lesser%20known%2Fused%20PHP%20functions%2C%20PHP%20uses%20in%20new%20creative%20ways.%0D%0A%0D%0AFirst%20up%20is%20substr%28%29%2C%20a%20simple%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;title=PHP%20tricks%3A%20substr%28%29" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;t=PHP%20tricks%3A%20substr%28%29&amp;s=I%27ve%20decided%20to%20start%20a%20new%20section%20on%20DavePCGuy%20that%20deals%20entirely%20with%20PHP%20tips%20%26amp%3B%20tricks.%20What%27s%20great%20about%20that%20is%20that%20I%20show%20you%20some%20of%20the%20lesser%20known%2Fused%20PHP%20functions%2C%20PHP%20uses%20in%20new%20creative%20ways.%0D%0A%0D%0AFirst%20up%20is%20substr%28%29%2C%20a%20simple%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=PHP%20tricks%3A%20substr%28%29%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=PHP%20tricks%3A%20substr%28%29&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=PHP%20tricks%3A%20substr%28%29&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fphp-tricks-substr%2F&amp;title=PHP%20tricks%3A%20substr%28%29" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/php-tricks-substr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some useful PHP functions</title>
		<link>http://www.davepcguy.com/archive/some-useful-php-functions/</link>
		<comments>http://www.davepcguy.com/archive/some-useful-php-functions/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 01:10:58 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1189</guid>
		<description><![CDATA[Recently, I have noticed that I use the same exact functions over and over again in PHP. I&#8217;ve actually set-up a complete function list that I tend to include in all of my projects. Here is an overview of some of them. Let&#8217;s connect You will need to connect to your database from time to]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=functions,php,programming&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently, I have noticed that I use the same exact functions over and over again in PHP. I&#8217;ve actually set-up a complete function list that I tend to include in all of my projects. Here is an overview of some of them.</p>
<h2>Let&#8217;s connect</h2>
<p>You will need to connect to your database from time to time. It is important to do that in most projects that deal with MySQL, and you&#8217;ll probably do it frequently, on every page. Now, you can either delete that &#8220;<strong>function CustomConnect</strong>&#8221; and the braces and simply <strong>include()</strong> this part as a file orrr, just add this to your function list and call it up whenever you need it:</p>
<p><span id="more-1189"></span></p>
<pre class="brush: php; title: ;">function CustomConnect () {

// MySQL variables
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database';

//connect
global $connection;
$connection = mysql_connect($host, $user, $pass) or die (&quot;Unable to connect!&quot;);
//database select
mysql_select_db($db) or die (&quot;Unable to select database!&quot;);
}
</pre>
<p>I have used this function numerous times before and yes, it works. This is the standard MySQL connection. I set up the variable <strong>$connection </strong>as <strong>global</strong> so that variable can be used outside of the function. Why do we need that? You will need that for your <strong>mysql_close() </strong>function where you will use <strong>$connection </strong>as your argument variable (inside the parentheses). That will, obviously, close the connection to the mysql database.</p>
<p>Change the username, password, and database according to your own website. Tweak the function as needed. I found it bare-boned and just as I need it for my purposes but you can add default variables, make it more of a &#8220;function&#8221; if you catch my drift.</p>
<h2>Let&#8217;s Authenticate</h2>
<p>Authentication is essential when creating an admin-side for a website. What does it mean? It means that PHP checks if you are, indeed, the logged in user, and if you have permission to see the site. The PHP is rather simple but effective!</p>
<pre class="brush: php; title: ;">function Authenticate () {
session_start();

if (!$_SESSION['auth'] == 1 || isset($_GET['logout'])) {
    // check if authentication was performed
    // else die with error
	session_destroy();
	header(&quot;Location: login.php&quot;);
}

}
</pre>
<p>First, we start a session, this tells the server that we are going to use a session. Next, with an &#8220;if&#8221; loop, we check if the session variable &#8220;auth&#8221; is set to one, change this however you need to to indicate that a user is logged in. The <strong>$_SESSION['']</strong> variable, if you did not know already, stores variable and information between pages. That means that you don&#8217;t need to keep using a &#8220;post&#8221; form to pass the data along. All of it is there in the session, and can be called up whenever.</p>
<p>As you can see, if either the authentication is not set or the <strong>$_GET['logout']</strong> variable is set, you will be redirected to login.php. Basically, this is how you log out! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  You can set up a button or a link to make this work.</p>
<p>This, again, is a bare-boned function. You can add global variables to call on the session variable <strong>username</strong> or other information.</p>
<h2>Let&#8217;s Validate</h2>
<p>This part is a bit harder.The way I validate is lengthy and redundant, very redundant. Perhaps even wasteful but it works for me and I can sleep soundly because everything is validate correctly. I set up SEVERAL functions to do this:</p>
<pre class="brush: php; title: ;">

function isEmailAddress($value) {
        return eregi('^([a-z0-9])+([\.a-z0-9_-])*@([a-z0-9_-])+(\.[a-z0-9_-]+)*\.([a-z]{2,6})$', $value);
    }

function isAlpha($value) {
        return preg_match('/^[a-zA-Z]+$/', $value);
    }
function Alphanum ($value) {
		return preg_match(&quot;/^[a-z0-9]+([\\s]{1}[a-z0-9]|[a-z0-9])+$/i&quot;, $value);
	}

function name ($var) {
	if (!isAlpha($var)){
	return TRUE;
	}
}

function email ($var) {
	if (!isset($var)){
	return TRUE;
	}
	if (empty($var)){
	return TRUE;
	}
	if (trim($var) == ''){
	return TRUE;
	}
	if (isEmailAddress($var) == 0){
	return TRUE;
	}
}
function message ($var) {
	if (!isset($var)){
	return TRUE;
	}
	if (empty($var)){
	return TRUE;
	}
	if (trim($var) == ''){
	return TRUE;
	}
</pre>
<p>I told you it was lengthy! All these functions are essential, you may combine some of the &#8220;if&#8221; statements together with an || or &amp;&amp; but I like to keep them separate. As you can see, there are two separate functions above that check for an e-mail address, this is done with pattern recognition. The next function <strong>isAlpha</strong> does the same but only for alpha characters, <strong>Alphanum</strong> does the same except that it includes numeric characters. The next three functions (<strong>name, email, </strong>and <strong>message</strong>) combine these along with a few &#8220;if&#8221; statements that check that data has, indeed been submitted via empty($var), trim($var), and other functions already included within PHP. Notice that you will be returned a <strong>TRUE </strong>value for all of these, meaning that if something is wrong, the result will be true. Use it like this:</p>
<pre class="brush: php; title: ;">
if (message($_GET['submittedmessage'])) { echo &quot;Something is wrong&quot;;}
</pre>
<p>And that&#8217;s it. If something is wrong, PHP will be echo out &#8220;Something is wrong&#8221;.</p>
<h2>Let&#8217;s show some stuff</h2>
<p>I like to keep handy one other function that deals with showing the latest entries in a MySQL database. I call it the &#8220;<strong>ShowComments</strong>&#8221; function because that is what I originally used it for. You will have to set up this function for each site you&#8217;ll use (ie. the rows and stuff like that) but here is what mine generally looks like:</p>
<pre class="brush: php; title: ;">
function ShowComments ($var, $where = '') {

$query = &quot;SELECT * FROM database_name $where ORDER BY id DESC&quot;;

    // execute query
    $result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());

	if (mysql_num_rows($result) &gt; 0) {
				$x = 1;
		while($row = mysql_fetch_row($result) AND $x &lt;= $var) :
			$link = $_SERVER['PHP_SELF'].&quot;?id=&quot;.$row[0];
       		echo &quot;&lt;p id=\&quot;to\&quot;&gt;To: &quot;.stripslashes($row[1]).&quot;&lt;/p&gt;&quot;;
        	echo &quot;&lt;p id=\&quot;message\&quot;&gt;&quot; .stripslashes($row[2]).&quot;&lt;/p&gt;&quot;;
			echo &quot;&lt;p id=\&quot;linktime\&quot;&gt;&lt;a href=&quot;.$link.&quot; title=\&quot;permalink&quot;.$row[0].&quot;\&quot;&gt;permalink&lt;/a&gt;  &quot;;
			echo substr($row[3], 0, 10).&quot;&lt;/p&gt;&quot;;
			echo &quot;&lt;/div&gt;
			&quot;;
			$x++;
		endwhile;
	}
}
</pre>
<p>I used this function on one of my latest projects (so ignore the id&#8217;s). You can add another parameter into the function to change table names on the go but I usually use this for only one table, such as comments, or a feed. I added the <strong>$where</strong> part so that I can pick out specific rows rather than just all of them at once. Note that you will have to write the entire &#8220;where&#8221; statement ie. <strong>WHERE id=4</strong> not just <strong>id=4</strong>, okay? Good.</p>
<p>Here&#8217;s an example of how I used it:</p>
<pre class="brush: php; title: ;">
&lt;?php
if (!isset($_GET['id'])) {
ShowComments(5);
}
else {
$id = mysql_real_escape_string($_GET['id']);
ShowComments(1, &quot;WHERE id='$id'&quot;);
}
</pre>
<p>Notice how I used it two separate times. Once to show the fave latest comments, the second time to show one specific comment with a specific (escaped) id.</p>
<p>Well, this is it. I hope these functions gave you some insight on how you can speed up your work! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong><br />
</strong></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;title=Some%20useful%20PHP%20functions&amp;bodytext=Recently%2C%20I%20have%20noticed%20that%20I%20use%20the%20same%20exact%20functions%20over%20and%20over%20again%20in%20PHP.%20I%27ve%20actually%20set-up%20a%20complete%20function%20list%20that%20I%20tend%20to%20include%20in%20all%20of%20my%20projects.%20Here%20is%20an%20overview%20of%20some%20of%20them.%0D%0ALet%27s%20connect%0D%0AYou%20will%20need%20to" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;title=Some%20useful%20PHP%20functions&amp;notes=Recently%2C%20I%20have%20noticed%20that%20I%20use%20the%20same%20exact%20functions%20over%20and%20over%20again%20in%20PHP.%20I%27ve%20actually%20set-up%20a%20complete%20function%20list%20that%20I%20tend%20to%20include%20in%20all%20of%20my%20projects.%20Here%20is%20an%20overview%20of%20some%20of%20them.%0D%0ALet%27s%20connect%0D%0AYou%20will%20need%20to" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;t=Some%20useful%20PHP%20functions" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;title=Some%20useful%20PHP%20functions&amp;annotation=Recently%2C%20I%20have%20noticed%20that%20I%20use%20the%20same%20exact%20functions%20over%20and%20over%20again%20in%20PHP.%20I%27ve%20actually%20set-up%20a%20complete%20function%20list%20that%20I%20tend%20to%20include%20in%20all%20of%20my%20projects.%20Here%20is%20an%20overview%20of%20some%20of%20them.%0D%0ALet%27s%20connect%0D%0AYou%20will%20need%20to" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;title=Some%20useful%20PHP%20functions&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Recently%2C%20I%20have%20noticed%20that%20I%20use%20the%20same%20exact%20functions%20over%20and%20over%20again%20in%20PHP.%20I%27ve%20actually%20set-up%20a%20complete%20function%20list%20that%20I%20tend%20to%20include%20in%20all%20of%20my%20projects.%20Here%20is%20an%20overview%20of%20some%20of%20them.%0D%0ALet%27s%20connect%0D%0AYou%20will%20need%20to" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;title=Some%20useful%20PHP%20functions" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;t=Some%20useful%20PHP%20functions&amp;s=Recently%2C%20I%20have%20noticed%20that%20I%20use%20the%20same%20exact%20functions%20over%20and%20over%20again%20in%20PHP.%20I%27ve%20actually%20set-up%20a%20complete%20function%20list%20that%20I%20tend%20to%20include%20in%20all%20of%20my%20projects.%20Here%20is%20an%20overview%20of%20some%20of%20them.%0D%0ALet%27s%20connect%0D%0AYou%20will%20need%20to" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Some%20useful%20PHP%20functions%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Some%20useful%20PHP%20functions&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Some%20useful%20PHP%20functions&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsome-useful-php-functions%2F&amp;title=Some%20useful%20PHP%20functions" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/some-useful-php-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When your project fails&#8230;</title>
		<link>http://www.davepcguy.com/archive/when-your-project-fails/</link>
		<comments>http://www.davepcguy.com/archive/when-your-project-fails/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 15:04:54 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[General Articles]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[webpage]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1088</guid>
		<description><![CDATA[A short what to do if your project fails. How to salvage the code, the files, and how to make the best of what happened]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=blog,php,web+design,webpage&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>So, let&#8217;s say you&#8217;re working on a project. It&#8217;s filled with your blood, sweat, and tears. You&#8217;ve been working on it through nights, barely sleeping at night, drinking large amounts of coffee during the day to stay up. Putting all into it. But then everything goes wrong.</p>
<p>Well, we&#8217;ve all been there, many times. If you&#8217;re a web-developer, it&#8217;s a natural part of your life. It&#8217;s a natural part of mine too. Let me tell you my story.<br />
</p>
<p><span id="more-1088"></span></p>
<h1>What happened?</h1>
<p>Well, recently, I was working on two project. The first was a bust, the second was scrapped. The first was Only A Quote and the second was an independent blogging system.</p>
<p><a rel="attachment wp-att-1091" href="http://www.davepcguy.com/archive/when-your-project-fails/projects1/"><img class="aligncenter size-medium wp-image-1091" title="project" src="http://www.davepcguy.com/wp-content/uploads/2010/01/projects1-300x149.jpg" alt="" width="300" height="149" /></a></p>
<p>How was Only A Quote a bust? Well, it was not ENTIRELY a bust. It receives good traffic, there&#8217;s great Ad Sense yields. The design is wonderful and the PHP is amazing <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It gets good ratings Google-wise but it&#8217;s nothing to be REALLY excited over. It was an important project to me because I spent COUNTLESS hours perfecting the script, learning PHP, CSS, and HTML. Basically, I spent my holiday break sweating over this project. I expected to sell the website for close to a thousand dollars but after a month of auctioning, it all ended with a hundred dollar bid.</p>
<p>Terrible.</p>
<p><a rel="attachment wp-att-1092" href="http://www.davepcguy.com/archive/when-your-project-fails/projects2/"><img class="aligncenter size-medium wp-image-1092" title="projects" src="http://www.davepcguy.com/wp-content/uploads/2010/01/projects2-300x166.jpg" alt="" width="300" height="166" /></a></p>
<p>The next project was a blogging system for a customer. I created a custom design, interface. Really intuitive too! Let&#8217;s just say, it was a jewel to me. It wasn&#8217;t perfect, but let&#8217;s just say I spent A TON of time figuring it out. There were no directions as to what the project should look like but that&#8217;s okay. I made an administration secure from any threats. Well, the whole deal. Imagine a simple wordpress-like blogging system. But, the client didn&#8217;t like it so I scrapped it and created a wordpress theme instead.</p>
<p>There is one more &#8220;failure&#8221;. Well, this one was not so bad because I was never counting on it in the first place, but it was damn annoying that nothing came out of it.</p>
<p><a rel="attachment wp-att-1093" href="http://www.davepcguy.com/archive/when-your-project-fails/projects3/"><img class="aligncenter size-medium wp-image-1093" title="projects" src="http://www.davepcguy.com/wp-content/uploads/2010/01/projects3-300x153.jpg" alt="" width="300" height="153" /></a>My &#8220;Age Tester&#8221;. My first PHP application. Well, the problem was that I had no way to advertise it well, I had no good domain name. And let&#8217;s just say, I suck at designing stuff like this haha. It&#8217;s still fun or whatever, and I send <a title="Age Tester" href="http://test.davepcguy.com/scripts/agetester/final.php">a link</a> to my friends once in a while when they ask me if their partner is too old or too young for them. But that&#8217;s it.</p>
<h1>How to deal with it?</h1>
<p>It&#8217;s always hard to deal with failure, especially when you&#8217;re failing and you think it&#8217;s entirely unfair. I can admit that the only project -I- relied on was OnlyAQuote but I&#8217;m sure you have had your own experiences where you had to rely on multiple projects that went bust.</p>
<p>So, there is no easy way to say this other than, Just SCAVENGE the project. Strip it clean! It sounds silly, but think of every website you work on as a beautiful creation full of priceless parts. When that beautiful creation becomes a horrendous ugly thing, take it apart.</p>
<p>Let me use my Bodyshop project as an example:</p>
<p><a rel="attachment wp-att-1094" href="http://www.davepcguy.com/archive/when-your-project-fails/projects4/"><img class="aligncenter size-medium wp-image-1094" title="projects4" src="http://www.davepcguy.com/wp-content/uploads/2010/01/projects4-300x171.jpg" alt="" width="300" height="171" /></a>The website has 57 files and 18 folders. Most of which is code and pictures. Well, all of it. There must be something worth it in there.</p>
<p>First of all, I took apart the whole admin area of the site and salvaged the scripts for my own script library. I have an authentication script there, add to database scripts, blogging scripts, well, a bunch of stuff. I even have an upload form (and those come in handy) as well as a mailing script. All of this work, better not go to waste. I can use ALL of these for my next projects.</p>
<p>Streamlined, secure authentication takes time to create, and here I have it, already done. I have a login form as well, so that&#8217;s done. Admin scripts and the blog script are the most important parts to me but there is more.</p>
<p>I can also use some of the images for the future. I created my own texture (as seen in the snapshot way above) that I can use for other project (involving metal and such). I also have a pretty decent car cut-out silhouette which I won&#8217;t have to work on next time I do something involving cars.Oh, and I have a pretty button to use <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a rel="attachment wp-att-1095" href="http://www.davepcguy.com/archive/when-your-project-fails/projects5/"><img class="aligncenter size-medium wp-image-1095" title="projects5" src="http://www.davepcguy.com/wp-content/uploads/2010/01/projects5-300x93.jpg" alt="" width="300" height="93" /></a></p>
<p>I couldn&#8217;t do the same for Only A Quote since I was selling the script, but I did bookmark all the scripts that were used from other programmers. (ie. web redirection)</p>
<p>All this takes is a bit of time, and tears that come along with stripping your project of its meat.</p>
<h1>Did you learn something?</h1>
<p>Making mistakes, and failure, it&#8217;s a process of learning! Did you learn something while making this project? I&#8217;m sure you have!</p>
<p>Now go write about it!</p>
<p>I&#8217;ve gotten some good traffic from the posts I based on the scripts I&#8217;ve written. Just check out this list:</p>
<ul>
<li><a title="Blogging System part 1" href="http://www.davepcguy.com/archive/creating-a-blogging-system-part-1/">Blogging system part 1</a></li>
<li><a title="Blogging System Part 2" href="http://www.davepcguy.com/archive/creating-a-blogging-system-part-2/">Blogging system part 2</a></li>
<li><a title="Mobile Website Tips" href="http://www.davepcguy.com/archive/mobile-websites-tips/">Mobile Site tips</a></li>
<li><a title="Database system" href="http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/">Shortlink API</a></li>
</ul>
<p>So, you&#8217;ve a lot of material you can write about. Plus, It&#8217;s rather nice if you share your secrets! Haha, I know I did. Some of this stuff took me a while to figure out, but, I got it down and now you can reap from my benefits, too.</p>
<p>Also, it sent a lot of traffic my way when I submitted these tutorials online. Double win! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h1>Conclusion</h1>
<p>Failures will teach you important lessons and can be salvagable, perhaps not to the original intent of goal, but good enough. Just, learn from your mistakes, okay? I know I did, and I&#8217;m sure you will too, over and over and over and over&#8230;again.<br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;title=When%20your%20project%20fails...&amp;bodytext=A%20short%20what%20to%20do%20if%20your%20project%20fails.%20How%20to%20salvage%20the%20code%2C%20the%20files%2C%20and%20how%20to%20make%20the%20best%20of%20what%20happened" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;title=When%20your%20project%20fails...&amp;notes=A%20short%20what%20to%20do%20if%20your%20project%20fails.%20How%20to%20salvage%20the%20code%2C%20the%20files%2C%20and%20how%20to%20make%20the%20best%20of%20what%20happened" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;t=When%20your%20project%20fails..." title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;title=When%20your%20project%20fails...&amp;annotation=A%20short%20what%20to%20do%20if%20your%20project%20fails.%20How%20to%20salvage%20the%20code%2C%20the%20files%2C%20and%20how%20to%20make%20the%20best%20of%20what%20happened" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;title=When%20your%20project%20fails...&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=A%20short%20what%20to%20do%20if%20your%20project%20fails.%20How%20to%20salvage%20the%20code%2C%20the%20files%2C%20and%20how%20to%20make%20the%20best%20of%20what%20happened" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;title=When%20your%20project%20fails..." title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;t=When%20your%20project%20fails...&amp;s=A%20short%20what%20to%20do%20if%20your%20project%20fails.%20How%20to%20salvage%20the%20code%2C%20the%20files%2C%20and%20how%20to%20make%20the%20best%20of%20what%20happened" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=When%20your%20project%20fails...%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=When%20your%20project%20fails...&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=When%20your%20project%20fails...&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhen-your-project-fails%2F&amp;title=When%20your%20project%20fails..." title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/when-your-project-fails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Creating a Blogging System (Part 2)</title>
		<link>http://www.davepcguy.com/archive/creating-a-blogging-system-part-2/</link>
		<comments>http://www.davepcguy.com/archive/creating-a-blogging-system-part-2/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:24:36 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1079</guid>
		<description><![CDATA[Okay, in my first tutorial, you learned about creating an install script for your blog as well as the entry form that will add your blogs. In this tutorial, I&#8217;ll teach you how to parse the data out for your audience and how to edit your entries. /* LET'S GET STARTED! */ Show off your]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=blog,functions,mysql,php,server&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Okay, in my first <a title="blogging system part1" href="http://www.davepcguy.com/archive/creating-a-blogging-system-part-1/">tutorial</a>, you learned about creating an install script for your blog as well as the entry form that will add your blogs.</p>
<p>In this tutorial, I&#8217;ll teach you how to parse the data out for your audience and how to edit your entries.</p>
<pre class="brush: php; title: ;">
/* LET'S GET STARTED! */
</pre>
<p><span id="more-1079"></span><br />
</p>
<h1>Show off your stuff!</h1>
<p>Haha, let&#8217;s get into how to show your blog posts to your readers. First, we need some pagination. Search for some scripts or tutorials on google and see if you can find anything. We all like different styles of pagination, and I&#8217;m not particularly awesome in custom paginating. If you can&#8217;t find anything good, use <a title="pagination" href="http://www.phpeasystep.com/phptu/29.html">the code I use</a>, just don&#8217;t use the styles, you can create your own.</p>
<p>If you&#8217;re using the script I do, or some other one that&#8217;s similar, you won&#8217;t have any trouble following this tutorial. Actually, you won&#8217;t have any trouble doing that anyways. Just make sure that the last MySQL query before the <strong>while() </strong>loop looks something like this:</p>
<pre class="brush: php; title: ;">
$sql = &quot;SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $start, $limit&quot;;
</pre>
<p>The important part of the query that we&#8217;re looking for is that &#8220;<strong>ORDER BY id DESC</strong>&#8221; part, it tells mysql to place the highest id in the front and the lowest in the back ie. the most recent posts will show at the beginning. The rest is up to the actual pagination script. If it doesn&#8217;t use limits, don&#8217;t worry about it. If you&#8217;re experiencing MySQL errors because of this, place the command elsewhere in the query, it should be close to the table_name selector.</p>
<p>Let&#8217;s move onto the <strong>while()</strong> loop. Every paginating script should ask you for the while loop, so let&#8217;s show them what we&#8217;ve got:</p>
<pre class="brush: php; title: ;">
	while($row = mysql_fetch_row($result)) {
		$content = stripslashes($row[3]);
		echo &quot;&lt;h1&gt;$row[1]&lt;/h1&gt;&quot;;
		echo &quot;&lt;h2&gt;$row[2]&lt;/h2&gt;&quot;;
		echo &quot;&lt;p&gt;.&quot;.$content.&quot;&lt;/p&gt;&quot;;
		echo &quot;&lt;br /&gt;&quot;;

	}
</pre>
<p>Simple enough? Let me explain it. The stuff inside the {} curly braces will repeat WHILE the stuff inside the () is true. Basically as long as there&#8217;s data present, what happens inside the curly braces will loop over and over. The insides of () basically mean that we&#8217;re storing data in the $row variable that corresponds to the $result from the previous $sql query. The function <strong>mysql_fetch_row</strong> just fetches the data and in the process puts it in the $row variable.</p>
<p>Do you remember our install script? This is what it looked like for our blog table:</p>
<pre class="brush: php; title: ;">
$query = &quot;CREATE TABLE blog
(
id int NOT NULL auto_increment primary key,
title blob NOT NULL,
date blob NOT NULL ,
content text NOT NULL
)&quot;;
</pre>
<p>Now, since in the computer language we start counting with 0 and not 1, it makes things a bit confusing. So column zero is id, column one is title etc. The inside of the while loop tells us to put column one as a title between &lt;h1&gt; tags, column two is the date and goes into &lt;h2&gt;tags, and column three is the content and goes into the &lt;p&gt; tags.</p>
<p>Now, I&#8217;ll assume that in my previous tutorial, you used the function <strong>mysql_real_escape_string()</strong> for escaping dangerous characters with the &#8220;\&#8221; backslash. Here&#8217;s where a problem arises. If you didn&#8217;t use the <strong>stripslashes()</strong> function you&#8217;d end up with something like this (example):</p>
<blockquote>
<h1>Here\&#8217;s the title</h1>
<h2>18-01-2010</h2>
<p>Here\&#8217;s the content of the blog. Aren\&#8217;t you excited? \:\)</p></blockquote>
<p>Okay, I don&#8217;t really think the smiley would be escaped like that but it could be! I don&#8217;t even bother with the rules anymore because it&#8217;s a lot easier to get it escaped with the function. The <strong>stripslashes()</strong> function is the opposite of the mysql_real_escape_string() function because all it does is take out the backslashes so the content looks proper. Remember that! It&#8217;s really important because you&#8217;ll be escaping A TON of strings!</p>
<p>But that&#8217;s it, give it some styling and you&#8217;ll have a lovely blog! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h1>Editing your Entries</h1>
<p>So, you can write and post blogs. Now what? Well, it&#8217;d be nice if you could edit those blogs just in case you made mistake, right?<br />
Well, let&#8217;s get on that. First, you&#8217;ll need to use the pagination script you used above in the SAME WAY, except with a different<strong> while()</strong> loop and some html before the loop. You can add this to the previous blog admin page where you added entries to the blog. It&#8217;s what I did.</p>
<p>Okay, so add the pagination script and this is what the while loop and the surrounding area looks like:</p>
<pre class="brush: php; title: ;">
&lt;?php
	echo &quot;&lt;table cellpadding=10 border=1&gt;&quot;;
	echo &quot;&lt;tr&gt;&quot;;
	echo &quot;&lt;td&gt;Id &lt;/td&gt;&quot;;
	echo &quot;&lt;td&gt;Title&lt;/td&gt;&quot;;
	echo &quot;&lt;td&gt;Date&lt;/td&gt;&quot;;
	echo &quot;&lt;td&gt;Delete&lt;/td&gt;&quot;;
	echo &quot;&lt;td&gt;Edit&lt;/td&gt;&quot;;
	echo &quot;&lt;/tr&gt;&quot;;

	while($row = mysql_fetch_row($result)) {
		$id = $row[0];
		echo &quot;&lt;tr&gt;&quot;;
        echo &quot;&lt;td&gt;$row[0]&lt;/td&gt;&quot;;
        echo &quot;&lt;td&gt;$row[1]&lt;/td&gt;&quot;;
        echo &quot;&lt;td&gt;$row[2]&lt;/td&gt;&quot;;
		echo &quot;&lt;td&gt;&lt;a href=\&quot;&quot;.$_SERVER['PHP_SELF'].&quot;?cmd=delete&amp;id=&quot;.$id.&quot;\&quot;&gt;Delete&lt;/a&gt;&lt;/td&gt;&quot;;
		echo &quot;&lt;td&gt;&lt;a href=\&quot;blogedit.php?id=&quot;.$id.&quot;\&quot;&gt;Edit&lt;/a&gt;&lt;/td&gt;&quot;;
		echo &quot;&lt;/tr&gt;&quot;;

	}
	echo &quot;&lt;/table&gt;&quot;;
?&gt;
</pre>
<p>Alright, what this basically does is create a table with the headings: id, title, date, delete, and edit. To that correspond the correct rows. Notice that I did not use <strong>stripslashes()</strong> on the entries, why? Because I honestly don&#8217;t care. You can use them, but for me, I just need to know the correct blog title, date, etc.</p>
<p>Onto, <strong>delete. </strong>Notice the URL, you&#8217;ll be adding &#8220;cmd=delete&amp;id=$id&#8221; to your original URL. What that is is basically manually adding GET information. Why do I do it this way? It&#8217;s easier than creating a complicated form with hidden values just for a pretty &#8220;delete&#8221; submit button. Next, you&#8217;ll notice that I&#8217;m doing the same thing with the GET but this time I am redirecting my page to a separate blogedit.php with the id information.</p>
<p>Let&#8217;s see how we can use that delete link first. I&#8217;m going to add a script at the beginning of the file that will DELETE this specific entry from the database.</p>
<pre class="brush: php; title: ;">
if ($_GET['cmd'] == &quot;delete&quot;)
{
	$id = $_GET['id'];
	$sql = &quot;DELETE FROM blog WHERE id=&quot;.$id;
    $result = mysql_query($sql);
    echo &quot;Blog &quot;.$id.&quot; deleted!&quot;;
}
</pre>
<p>What this says is basically that if the &#8220;cmd&#8221; $_GET variable is equal to &#8220;delete&#8221; then execute the loop. Inside the loop I defined the $id variable and used an SQL query that delete the entry. Notice that I did not mysql_real_escape_string() the $id variable. Once again, I am hoping that you know what you&#8217;re doing and that you won&#8217;t be purposely SQL injecting and messing up your database.</p>
<p>If you want more assurance that this got done (ie. the blog post got delete), you can make a separate if statement inside:</p>
<pre class="brush: php; title: ;">
if (isset($result)) {
     echo &quot;Blog &quot;.$id.&quot; deleted!&quot;;
}
else {
   echo &quot;Blog post: &quot;.$id.&quot; not deleted!&quot;;
}
</pre>
<p>Let&#8217;s move onto blogedit.php. Don&#8217;t forget to include the connection.php file.</p>
<p>This part should be pretty easy. Let&#8217;s start with a loop asking if you&#8217;re even on the right page (with the right information) and processing the data.</p>
<pre class="brush: php; title: ;">
if (isset($_GET['id'])){
		$id = mysql_real_escape_string($_GET['id']);
		$sql = &quot;SELECT * FROM blog WHERE id = '$id'&quot;;
		$result = mysql_query($sql) or die (&quot;Error in query: $query. &quot;.mysql_error());
		$row = mysql_fetch_row($result);
		}
</pre>
<p>This bit takes care of all the information. So yay! We&#8217;ve already executed the SQL to get the data and fetched it and stored inside the $row variable. I&#8217;ve mysql_real_escape_string() this one, but once again, it&#8217;s all up to you as to what you escape and what you don&#8217;t.With this done, we can move on to parse out the information in an editable form.</p>
<p>I want to be able to edit the blog the same way I edit in wordpress, or the way I add the blog. I just want the information to show up inside the appropriate fields!</p>
<p>Well, here&#8217;s how you do it:</p>
<pre class="brush: xml; title: ;">
   &lt;h2&gt;ID = &lt;?php echo $row[0];?&gt;&lt;/h2&gt;
    &lt;h2&gt;DATE = &lt;?php echo $row[2];?&gt;&lt;/h2&gt;
    &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $_SERVER['PHP_SELF'];?&gt;&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;title&quot; value=&quot;&lt;?php echo $row[1]; ?&gt;&quot; size=&quot;100&quot; / &gt;&lt;br /&gt;
    &lt;textarea rows=&quot;25&quot; cols=&quot;125&quot; name=&quot;content&quot;&gt;&lt;?php echo stripslashes($row[3]);?&gt;&lt;/textarea&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;&lt;?php echo $row[0];?&gt;&quot; /&gt;
    &lt;br /&gt;
    &lt;input type=&quot;submit&quot; name=&quot;update&quot; value=&quot;Update&quot; /&gt;
    &lt;/form&gt;
</pre>
<p>Okay, first things first. I want the blog ID and Date. Echo it out, done! Next, we&#8217;ll create a form with a self action and with the post method (just like in the first tutorial, we don&#8217;t want long URLs because of GET requests). Next, we&#8217;ll use the same form we did for the blog entry form but, we add the corresponding values. Notice that I used stripslashes() for the content again. You don&#8217;t want to get everything double slashed in the end, you&#8217;d have to double stripslashes() for your readers. Anyways, i think the rest is self-explanatory. The data will show up in the appropriate fields, you can add it and press &#8220;update&#8221; to get everything done.</p>
<p>NEXT! The loop that will make ALL of this happen:</p>
<pre class="brush: php; title: ;">
if (isset($_POST['update'])) {
		$id = mysql_real_escape_string($_POST['id']);
		$title = mysql_real_escape_string($_POST['title']);
		$content = mysql_real_escape_string($_POST['content']);
		$sql = &quot;UPDATE blog SET title = '$title', content = '$content' WHERE id = '$id'&quot;;
		$result = mysql_query($sql) or die (&quot;Error in query: $query. &quot;.mysql_error());

		if ($result) {
			echo &quot;Blog id = $id updated&quot;;
		}

}
</pre>
<p>Yep, whenever you press that pretty &#8220;update&#8221; button, this will take place. The blog gets update with everything escaped as it should be. And, look! I finally have that $result loop there! It looks like even I learned something from this tutorial <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h1>What&#8217;s up next?</h1>
<p>Well, in my next tutorial. I will FINALLY cover the login system and authorization stuff. It&#8217;s pretty easy but I want everyone to digest this info and ask away if you need anything!</p>
<h1>STUFF TO REMEMBER</h1>
<ul>
<li>Put <strong>include(connection.php); </strong>at the beginning of every SQL using file!</li>
<li>The <strong>while() </strong>loop puts all that data from your database to use!</li>
<li>MySQL columns are marked starting with ZERO, NOT ONE!</li>
<li>Use the <strong>stripslashes() </strong>function to counteract <strong>mysql_real_escape_string()</strong> function!</li>
<li>The ?id=23&amp;cmd=edit blah blah stuff is manually inserted GET variable information</li>
<li>Put all of the loops that do the hard work at the BEGINNING of the page!</li>
</ul>




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;title=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;bodytext=Okay%2C%20in%20my%20first%20tutorial%2C%20you%20learned%20about%20creating%20an%20install%20script%20for%20your%20blog%20as%20well%20as%20the%20entry%20form%20that%20will%20add%20your%20blogs.%0D%0A%0D%0AIn%20this%20tutorial%2C%20I%27ll%20teach%20you%20how%20to%20parse%20the%20data%20out%20for%20your%20audience%20and%20how%20to%20edit%20your%20entries.%0D%0A" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;title=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;notes=Okay%2C%20in%20my%20first%20tutorial%2C%20you%20learned%20about%20creating%20an%20install%20script%20for%20your%20blog%20as%20well%20as%20the%20entry%20form%20that%20will%20add%20your%20blogs.%0D%0A%0D%0AIn%20this%20tutorial%2C%20I%27ll%20teach%20you%20how%20to%20parse%20the%20data%20out%20for%20your%20audience%20and%20how%20to%20edit%20your%20entries.%0D%0A" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;t=Creating%20a%20Blogging%20System%20%28Part%202%29" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;title=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;annotation=Okay%2C%20in%20my%20first%20tutorial%2C%20you%20learned%20about%20creating%20an%20install%20script%20for%20your%20blog%20as%20well%20as%20the%20entry%20form%20that%20will%20add%20your%20blogs.%0D%0A%0D%0AIn%20this%20tutorial%2C%20I%27ll%20teach%20you%20how%20to%20parse%20the%20data%20out%20for%20your%20audience%20and%20how%20to%20edit%20your%20entries.%0D%0A" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;title=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Okay%2C%20in%20my%20first%20tutorial%2C%20you%20learned%20about%20creating%20an%20install%20script%20for%20your%20blog%20as%20well%20as%20the%20entry%20form%20that%20will%20add%20your%20blogs.%0D%0A%0D%0AIn%20this%20tutorial%2C%20I%27ll%20teach%20you%20how%20to%20parse%20the%20data%20out%20for%20your%20audience%20and%20how%20to%20edit%20your%20entries.%0D%0A" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;title=Creating%20a%20Blogging%20System%20%28Part%202%29" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;t=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;s=Okay%2C%20in%20my%20first%20tutorial%2C%20you%20learned%20about%20creating%20an%20install%20script%20for%20your%20blog%20as%20well%20as%20the%20entry%20form%20that%20will%20add%20your%20blogs.%0D%0A%0D%0AIn%20this%20tutorial%2C%20I%27ll%20teach%20you%20how%20to%20parse%20the%20data%20out%20for%20your%20audience%20and%20how%20to%20edit%20your%20entries.%0D%0A" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Creating%20a%20Blogging%20System%20%28Part%202%29%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Creating%20a%20Blogging%20System%20%28Part%202%29&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-2%2F&amp;title=Creating%20a%20Blogging%20System%20%28Part%202%29" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/creating-a-blogging-system-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a Blogging system (part 1)</title>
		<link>http://www.davepcguy.com/archive/creating-a-blogging-system-part-1/</link>
		<comments>http://www.davepcguy.com/archive/creating-a-blogging-system-part-1/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 02:26:53 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1070</guid>
		<description><![CDATA[Some time ago (a couple weeks), I created my own blogging system. No one told me how to do it and I didn&#8217;t read any tutorials on how to do it either so there were a few things I learned the hard way. As you know, Blogs are database-based, they&#8217;re all entries in a table.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=blog,functions,HTML%2FCSS,mysql,php,server&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Some time ago (a couple weeks), I created my own blogging system. No one told me how to do it and I didn&#8217;t read any tutorials on how to do it either so there were a few things I learned the hard way. As you know, Blogs are database-based, they&#8217;re all entries in a table.</p>
<p>You have an entry for the id, date, the content, and miscellaneous other information such as tags, and description. In this tutorial, I&#8217;d like to teach you how to do all that.</p>
<pre class="brush: php; title: ;">
/* LET'S GET STARTED!*/
</pre>
<p><span id="more-1070"></span><br />
</p>
<h1>Creating The Table</h1>
<p>For this tutorial, you&#8217;ll have to have your own database, and username. Set up a <a title="Setting up Part 1" href="http://www.davepcguy.com/archive/setting-up-part-1/">home server</a>, with WAMP, XAMPP or whatever else. Once you have that done, create that database, I&#8217;ll call mine &#8220;blog&#8221;.</p>
<p>I&#8217;m not going to get into how to do that, because if you&#8217;re doing this on a server online, you&#8217;ll need special instructions. Google it and set it up.</p>
<p>So, let&#8217;s create an INSTALL script. Make sure that when you use this script, delete it right after:</p>
<pre class="brush: php; title: ;">
&lt;?php

if (!isset($_POST['submit'])) {
?&gt;
&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;&quot;&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Install&quot;&gt;
&lt;/form&gt;

&lt;?php
}
</pre>
<p>This creates an installing button. This is only for convenience. I don&#8217;t like scripts that automatically add new tables and such without control.</p>
<pre class="brush: php; title: ;">
else {
include ('connection.php');
</pre>
<p>This little bit will connect you to the database. Here&#8217;s what my connection.php looks like:</p>
<pre class="brush: php; title: ;">
&lt;?php
// MySQL variables
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'blog';

//connect
$connection = mysql_connect($host, $user, $pass) or die (&quot;Unable to connect!&quot;);
//database select
mysql_select_db($db) or die (&quot;Unable to select database!&quot;);
?&gt;
</pre>
<p>Great, now you&#8217;re in the system (btw, you&#8217;ll have to make your own username, password, database, and all that, just like I said you&#8217;d have to do. Let&#8217;s move on to creating your administration for your site:</p>
<pre class="brush: php; title: ;">
//creating a user table
$query = &quot;CREATE TABLE users
(
name varchar(15),
pass varchar(255)
)&quot;;

$result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());

//making the user name
$password = md5('password you want to use');
$query=&quot;INSERT INTO users (name, pass)
VALUES
('admin', '$password')&quot;;

//query
$result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());
</pre>
<p>Great, now you have a database entry for your user (that&#8217;s you!), I won&#8217;t get into having multiple users, right now. So bear with me. I&#8217;m using a md5 hash to make the password a bit harder to crack. Also, I&#8217;m using the usual &#8220;admin&#8221; for username. Let&#8217;s move on to the blog table:</p>
<pre class="brush: php; title: ;">
//creating a blog table
 $query = &quot;CREATE TABLE blog
(
id int NOT NULL auto_increment primary key,
title blob NOT NULL,
date blob NOT NULL ,
content text NOT NULL
)&quot;;
    // execute query
    $result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());

$query = &quot;INSERT INTO blog (title, date, content) VALUES ('Welcome', 'May 5th', 'First blog entry! Aren\'t you excited?');
&quot;;
	// execute query
    $result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());

mysql_close($connection);
echo &quot;Done&quot;;

}
</pre>
<p>With this, we just created a simple blog table that will have a specific id, date, title, and content. We&#8217;ve also added a dummy entry (with a date format I won&#8217;t be using by the way).<br />
If you&#8217;re wondering about the backslash in the word &#8220;Aren&#8217;t&#8221;, don&#8217;t wonder anymore. A backslash is used to &#8220;escape&#8221; characters that may hold a different meaning in the world of programming languages.<br />
For example, if I did not escape that character, I would probably get an error where the MySQL wonders what the &#8220;t you excited?&#8221; is about since the entry ended at &#8220;aren&#8217;&#8221;.</p>
<p>Before we go on, I would like to seriously address this. The best way to avoid an error is to use a well-known php function <strong>mysql_real_escape_string()</strong>. This function will automatically add backslashes to all potentially problematic characters. Also, if you use this function, don&#8217;t add extra backslashes because the function will escape those as well. There&#8217;s only one problem with that function but I&#8217;ll show you the solution later on.</p>
<h1>Coding the Entry</h1>
<p>Now, you&#8217;ll notice that while coding the entry, I&#8217;m leaving the system open to vulnerabilities, but that&#8217;s okay. Why is it okay? Well, unless you&#8217;re logged in, you won&#8217;t be able to get into the system. So you should be the only one who gets in there and adds entries.</p>
<p>You can screw up your entries by dropping tables and whatnot if you want to, but I&#8217;ll assume you won&#8217;t be making any crazy MySQL stuff. Also, you&#8217;ll have the above-mentioned function to protect you from any unfortunate mistakes.</p>
<p>First add the connection.php file using the <strong>include()</strong> function. Second, let&#8217;s create the form:</p>
<pre class="brush: xml; title: ;">
&lt;h2&gt;Add Blog Post&lt;/h2&gt;
     &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $_SERVER['PHP_SELF'];?&gt;&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;title&quot; size=&quot;50&quot; / &gt;&lt;br /&gt;
    &lt;textarea name=&quot;content&quot; cols=&quot;150&quot; rows=&quot;20&quot;&gt;&lt;/textarea&gt;
    &lt;br /&gt;
    &lt;input type=&quot;submit&quot; name=&quot;addpost&quot; value=&quot;Add Post!&quot; /&gt;
    &lt;/form&gt;
</pre>
<p>Place this in the body of your html file, I know it sounds redundant and you should know about this stuff but I&#8217;m just making sure. What this form will do is send some information using the &#8220;post&#8221; method (ie. no URL mumbo jumbo like this: ?dkjw=fsjklwe&amp;fjskl=ewjk) No one wants a three thousand character URL up there (what browser would support that anyways?). You have two separate pieces of information: textarea (where your content goes) and input type=&#8221;text&#8221; (that&#8217;s the title). Anyways, put the next piece of code inside the &lt;head&gt; tag, or at least above the form.</p>
<pre class="brush: php; title: ;">if (isset($_POST['addpost'])) {
		$title = mysql_real_escape_string($_POST['title']);
		$content = mysql_real_escape_string($_POST['content']);
		$date = mysql_real_escape_string(date('m-d-Y'));
		$sql = &quot;INSERT INTO blog (title, date, content) VALUES ('$title', '$date', '$content')&quot;;
		$result = mysql_query($sql) or die (&quot;Error in query: $query. &quot;.mysql_error());

		if ($result) {
			echo &quot;Blog id = &quot;.$id.&quot; updated&quot;;
		}

}
</pre>
<p>Well, that&#8217;s some good stuff. The submit button in the form sent the post variable name &#8220;addpost&#8221; with the value &#8220;Add Post!&#8221;. The loop above goes into motion right when that post variable is submitted. I escaped all the strings just in case. Oh, if you didn&#8217;t know, you can use html, css, and all that other stuff in your posts. It won&#8217;t screw up anything, I promise <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyways, you can see I used a date function to specify the date the blog was submitted. <a title="date function PHP manual" href="http://php.net/manual/en/function.date.php">Read </a>up more about it if you want to use a different time stamp. This one looks like this &#8220;1-13-2010&#8243;. We then added all the values we needed into the database. And voila, we just added our first entry!</p>
<h1>What&#8217;s next?</h1>
<p>In my next tutorial, I&#8217;ll show you how to correctly show all that data! I&#8217;ll also get into how to protect your administration sites and how to create the login site too.</p>
<h1>STUFF TO REMEMBER</h1>
<ul>
<li>MySQL uses a lot of special characters. To avoid an error use the<strong> mysql_real_escape_string() </strong>which will sanitize your entries to some extent. There&#8217;s one small problem with the function, but I&#8217;ll address that in the next tutorial</li>
<li>Use the <strong>include()</strong> function for your connection.php file for each site that connects to the MySQL database. It&#8217;s easier than rewriting the code numerous times (especially if you decide to change the user name and all that)</li>
<li>Delete the <strong>install.php </strong>installation script after you&#8217;re done. You don&#8217;t want anyone messing with your scripts. It also creates a vulnerability if you leave it on the server. If you think you&#8217;ll forget, get on PHPmyAdmin and do all the querying manually.</li>
<li>HAVE FUN!</li>
</ul>




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;title=Creating%20a%20Blogging%20system%20%28part%201%29&amp;bodytext=Some%20time%20ago%20%28a%20couple%20weeks%29%2C%20I%20created%20my%20own%20blogging%20system.%20No%20one%20told%20me%20how%20to%20do%20it%20and%20I%20didn%27t%20read%20any%20tutorials%20on%20how%20to%20do%20it%20either%20so%20there%20were%20a%20few%20things%20I%20learned%20the%20hard%20way.%20As%20you%20know%2C%20Blogs%20are%20database-based%2C%20they%27re%20all" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;title=Creating%20a%20Blogging%20system%20%28part%201%29&amp;notes=Some%20time%20ago%20%28a%20couple%20weeks%29%2C%20I%20created%20my%20own%20blogging%20system.%20No%20one%20told%20me%20how%20to%20do%20it%20and%20I%20didn%27t%20read%20any%20tutorials%20on%20how%20to%20do%20it%20either%20so%20there%20were%20a%20few%20things%20I%20learned%20the%20hard%20way.%20As%20you%20know%2C%20Blogs%20are%20database-based%2C%20they%27re%20all" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;t=Creating%20a%20Blogging%20system%20%28part%201%29" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;title=Creating%20a%20Blogging%20system%20%28part%201%29&amp;annotation=Some%20time%20ago%20%28a%20couple%20weeks%29%2C%20I%20created%20my%20own%20blogging%20system.%20No%20one%20told%20me%20how%20to%20do%20it%20and%20I%20didn%27t%20read%20any%20tutorials%20on%20how%20to%20do%20it%20either%20so%20there%20were%20a%20few%20things%20I%20learned%20the%20hard%20way.%20As%20you%20know%2C%20Blogs%20are%20database-based%2C%20they%27re%20all" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;title=Creating%20a%20Blogging%20system%20%28part%201%29&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Some%20time%20ago%20%28a%20couple%20weeks%29%2C%20I%20created%20my%20own%20blogging%20system.%20No%20one%20told%20me%20how%20to%20do%20it%20and%20I%20didn%27t%20read%20any%20tutorials%20on%20how%20to%20do%20it%20either%20so%20there%20were%20a%20few%20things%20I%20learned%20the%20hard%20way.%20As%20you%20know%2C%20Blogs%20are%20database-based%2C%20they%27re%20all" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;title=Creating%20a%20Blogging%20system%20%28part%201%29" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;t=Creating%20a%20Blogging%20system%20%28part%201%29&amp;s=Some%20time%20ago%20%28a%20couple%20weeks%29%2C%20I%20created%20my%20own%20blogging%20system.%20No%20one%20told%20me%20how%20to%20do%20it%20and%20I%20didn%27t%20read%20any%20tutorials%20on%20how%20to%20do%20it%20either%20so%20there%20were%20a%20few%20things%20I%20learned%20the%20hard%20way.%20As%20you%20know%2C%20Blogs%20are%20database-based%2C%20they%27re%20all" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Creating%20a%20Blogging%20system%20%28part%201%29%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Creating%20a%20Blogging%20system%20%28part%201%29&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Creating%20a%20Blogging%20system%20%28part%201%29&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcreating-a-blogging-system-part-1%2F&amp;title=Creating%20a%20Blogging%20system%20%28part%201%29" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/creating-a-blogging-system-part-1/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Mobile Websites (tips)</title>
		<link>http://www.davepcguy.com/archive/mobile-websites-tips/</link>
		<comments>http://www.davepcguy.com/archive/mobile-websites-tips/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 23:28:37 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1051</guid>
		<description><![CDATA[I&#8217;ve recently started working on some mobile websites. You&#8217;ll notice that davepcguy.com has its own mobile alternative as do some other sites. Mobile devices are growing in number and gone are those days when internet was viewed only on the computer screen. WAP is not even used either so that old school coding is gone]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=css,Design,HTML%2FCSS,mobile,php,webpage,website&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve recently started working on some mobile websites. You&#8217;ll notice that davepcguy.com has its own mobile alternative as do some other sites. Mobile devices are growing in number and gone are those days when internet was viewed only on the computer screen. WAP is not even used either so that old school coding is gone too.</p>
<p>These days, almost everyone has an iPhone or a BlackBerry, or a Palm device. Some of us even have other devices like PSPs, tablets, and others that require quite a bit different formatting. Here&#8217;s how to go about making your mobile website.<br />
<span id="more-1051"></span><br />
</p>
<h1>Step 1 &#8211; The Vision</h1>
<p>First, you gotta have a vision of what you want. The best way to get a good vision is by picking up your phone and browsing the internet, looking through some popular websites such as <a title="Youtube" href="http://www.youtube.com">youtube</a>, <a title="Flickr" href="http://www.flickr.com">flickr</a>, <a title="Facebook" href="http://www.facebook.com">facebook</a>, <a title="Myspace" href="http://www.myspace.com">myspace</a>, and other sites that you know get a lot of traffic and are likely to have their own mobile version.</p>
<p>I recently saw a really nice blog <a title="Woorkup" href="http://woorkup.com/2010/01/10/best-practices-to-develop-perfect-websites-for-iphone-and-mobile-devices/">post</a> detailing some of the nicer mobile sites. The theme there is common:</p>
<p><a rel="attachment wp-att-1052" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile1/"><img class="aligncenter size-full wp-image-1052" title="mobile1" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile1.png" alt="" width="380" height="448" /></a>Everything is single column. There are no side-bars, there are no fancy tabs. Everything is in a single column. Think of it as a letter. There are no columns in a letter, you have a header, the body, and the footer.</p>
<ol>
<li>Header: Generally, you&#8217;ll use the header of the page to announce the website&#8217;s name and to show menu links. You may also place a commercial in this area (Google Adsense uses commercials). Here&#8217;s what I used on my <a title="Mobile Only A Quote" href="http://m.onlyaquote.com">Only A Quote</a> mobile site: <a rel="attachment wp-att-1053" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile2/"><img class="aligncenter size-full wp-image-1053" title="mobile2" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile2.png" alt="" width="298" height="62" /></a>It&#8217;s a simple banner that effectively tells the user what&#8217;s going on.</li>
<li>Body: This is pretty self-explanatory, you put the meet of your site here. Try to use well organized information. Don&#8217;t just slap stuff there. Mobile users are more likely to leave your site than regular computer users. Also, keep the graphics swift! Not too much.</li>
<li>Footer: Use the footer for copyright info and other blah blah stuff but don&#8217;t over do it! I know huge footers are fashionable but not for mobile users!</li>
</ol>
<p>Keep it all simple!</p>
<h1>Step 2 &#8211; Design</h1>
<p>Here are a few tools that will help you with your design:</p>
<ul>
<li><a title="iPhone tester" href="http://iphonetester.com/">iPhone tester</a></li>
<li><a title="mobile emulators" href="http://mobiforge.com/emulators/page/mobile-emulators">Mobile Emulators</a></li>
<li>more <a title="mobile emulators" href="http://www.klauskomenda.com/archives/2008/03/17/testing-on-mobile-devices-using-emulators/">mobile emulators</a></li>
</ul>
<p>Keep in mind that different phones will render your page differently so try to make it as simple as possible. To catch the widest possible audience, focus on the big three: iPhones, BlackBerries, and Palm phones. Samsung and Nokias are common too, especially outside of the US but BBs and iPhones capture most of the market. Android is coming up too, so watch out for them too.</p>
<p>A few simple rules:</p>
<ul>
<li>Keep the site less then 400px wide.</li>
<li>Cross-browsing is a bitch on Computers, it&#8217;s worse on phones, render for Safari and Opera Mobile</li>
<li>Graphics should not exceed 20kbs</li>
<li>Keep the layout basic</li>
</ul>
<p>There are tons  more rules but those are the basics.</p>
<h1>Step 3 &#8211; Coding</h1>
<p>First of all, DON&#8217;T USE JAVASCRIPT! It works on a lot of phones, it&#8217;s gaining support, but it&#8217;s really bothersome (I know, I use my phone to browse the net a lot). There&#8217;s no need for it. Hover and other pretty stuff is useless too. Many phones don&#8217;t support it.</p>
<p>Use as little mark-up code as you can. If your original site has thirty divs, make it three in this one. There&#8217;s no need for all that on phones. If your CSS screws up, so will your divs.</p>
<p>Use the following doctype:</p>
<pre class="brush: xml; title: ;">
&lt;!DOCTYPE html PUBLIC &quot;-//WAPFORUM//DTD XHTML Mobile 1.2//EN&quot;&quot;http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd&quot;&gt;
</pre>
<p>This will tell the browser that it&#8217;s meant for phones. It&#8217;ll help rendering and it&#8217;s the RIGHT thing to do haha. Once you start coding, again, keep in mind that your website should be the smallest possible.</p>
<p>Here are a couple of rules to keep in mind:</p>
<ol>
<li>Don&#8217;t use px/em sizes, do everything in percentages, you never know what kind of a phone the user will use.</li>
<li>Keep all files as small as possible.</li>
<li>If your .PNG graphics do not use transparency, convert them to JPGs with smaller quality</li>
<li>If you use .PNG graphics WITH transparency, consider remaking them into JPGs or GIFs (for transparency) if at all possible</li>
<li>Keep all graphics less than 400px wide. I suggest 350px tops.</li>
<li>Use &#8220;ALT&#8221; for images, some phones may not render the text and it&#8217;s standard .mobi rule</li>
<li>Try not to use tables or javascript</li>
<li>Don&#8217;t use external resources (ie pictures from other sites, scripts from other sites, etc)</li>
<li>Define sizes for images with the width = &#8220;&#8221; and height = &#8220;&#8221; html tags</li>
<li>NO POP UPS!</li>
</ol>
<p>That&#8217;s about it.</p>
<h1>Step 4 &#8211; Testing</h1>
<p>You&#8217;ll need to test your site, so use the resources mentioned in the emulator part. Use your phone as well!</p>
<p>Here&#8217;s another resource that will catch ALL of your mistakes:</p>
<p><a title="ready mobi" href="http://ready.mobi/">Ready.mobi</a></p>
<p>This site checks your markup, the size of your site, and many other features. It will tell you if you did something wrong and will usually tell you what you can fix on your site. It also features five different phone emulators on the spot. It also ranks the speed of your site. Here are my stats:</p>
<p><a rel="attachment wp-att-1054" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile3/"><img class="aligncenter size-medium wp-image-1054" title="mobile3" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile3-300x255.png" alt="" width="300" height="255" /></a>Oh yeah, that&#8217;s a bad rating. It&#8217;s mostly because of all the graphics on my site, the CSS involved and inter-linking on my blog. It happens but it does pretty well on my BlackBerry so try to look at your rating positively especially after you do your own tests. As you can see, it tells you the different speeds with GPRS, 3G, and Wi-fi.</p>
<h1>Step 5 &#8211; Implementation</h1>
<p>Let me save you a few hours of searching. In implementation, you&#8217;ll have to figure out how exactly you&#8217;re going to redirect your traffic to the mobile version whence they use their phones. It took some time for me to figure out but here are a few options:</p>
<ol>
<li><a title="detect mobile browsers" href="http://detectmobilebrowsers.mobi/">DetectMobileBrowsers</a> &#8211; This is almost a fullproof method of redirecting your traffic. The problem? You can&#8217;t use it unless your site is COMPLETELY non-profit. Nope, not even ads are allowed. If you want the commercial version, it will cost you $50 a year to use it</li>
<li><a title="Light Weight Device Detection" href="http://mobiforge.com/developing/story/lightweight-device-detection-php">LightWeight Device Detection</a> &#8211; This is probably one of the simplest scripts you&#8217;ll find and it works really well. It also doesn&#8217;t have any restrictions as far as I&#8217;m aware.</li>
<li><a title="Mobile Detect" href="http://www.jooria.com/scripts/Wireless-and-Mobile-156/Mobile-Detect-923/index.html">Mobile Detect</a> &#8211; This is a slightly more functional version of the above-mentioned Device Detection. They&#8217;re not related but work in a similar way</li>
</ol>
<p>Let&#8217;s move on to actually using these scripts. I haven&#8217;t used number one but I&#8217;ll tell you how you can incorporate number 2 and 3.</p>
<ol>
<li>Decide whether you want a separate site for the mobile version. I recommend creating a sub-domain such as m.onlyaquote.com (whence using sub-domains, remember that m.onlyaquote.com = onlyaquote.com/m )</li>
<li>If you did not create a separate sub-domain, you can place the whole thing in a loop but don&#8217;t forget to create a backdoor so that the user can switch between the desktop and mobile version.</li>
<li>Put all the script messy stuff into a separate file (so as not to clutter up your index.php file) except for the if/else statement found in number 2. If you&#8217;re using number 3, don&#8217;t worry about that at all.</li>
<li>Use <strong>include(script file ); </strong>to put the script back into your index.php file. Put all of your PHP before the &lt;html&gt; tag</li>
</ol>
<p>If you&#8217;re using Number 2, here&#8217;s what you do:</p>
<pre class="brush: php; title: ;">
include ('scriptfile.php');
if($mobile_browser&gt;0) {
   // do something
header( 'Location: mobilesite.com' ) ;
}
</pre>
<p>If you&#8217;re not using a different site do this:</p>
<pre class="brush: php; title: ;">
include('scriptfile.php');
if($mobile_browser&gt;0) {
 // place your mobile site here.
}
else {
   // place your desktop version here
}
</pre>
<p>You can also simply switch out CSS files with this method (make sure to put the loop inside the &lt;head&gt; tag then). I don&#8217;t suggest you use the default CSS method of switching styling according to the device (ie. &lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;css/quotestyles.css&#8221; media=&#8221;handheld&#8221; /&gt;) because it doesn&#8217;t work that well and most devices will try to read BOTH stylesheets.</p>
<p>For number 3, again place the following loop before the &lt;html&gt; tag:</p>
<pre class="brush: php; title: ;">
include(&quot;Mobile_Detect.php&quot;);
$detect = new Mobile_Detect();
if ($detect-&gt;isMobile()) {
    // any mobile platform
header( 'Location: mobilesite.com' ) ;
}
</pre>
<p>With the number 3 method (ie. <a title="mobile detect" href="http://www.jooria.com/scripts/Wireless-and-Mobile-156/Mobile-Detect-923/index.html">Mobile Detect</a>) you can also specify which mobile device you want to do what. You can choose a separate site for an iPhone and Blackberry or separate CSS files. Well, whatever, you can do it all.</p>
<p>CAUTION: The detection system is NOT perfect. With newer phones, newer browsers, and newer software, the detection script may become obsolete. Be always on the look out for better versions!</p>
<h1>Conclusion</h1>
<p>That&#8217;s it, with these few tricks, you should be able to easily make your own mobile site. Here&#8217;s what mine looks like (I still have a TON of work to do!):</p>
<p><a rel="attachment wp-att-1055" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile4/"><img class="aligncenter size-medium wp-image-1055" title="mobile4" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile4-228x300.png" alt="" width="228" height="300" /></a><br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;bodytext=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;notes=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;t=Mobile%20Websites%20%28tips%29" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;annotation=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;t=Mobile%20Websites%20%28tips%29&amp;s=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Mobile%20Websites%20%28tips%29%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Mobile%20Websites%20%28tips%29&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Mobile%20Websites%20%28tips%29&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/mobile-websites-tips/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Bit.ly API and adding URLs to your MySQL database</title>
		<link>http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/</link>
		<comments>http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 22:16:10 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[url-shortener]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1011</guid>
		<description><![CDATA[In my last tutorial, I&#8217;ve touched on how to use the to.ly API and how to make automatic &#8220;Tweet it&#8221; buttons with a relevant message. Well, this can get problematic if with every page refresh, your server sends out a request to the to.ly server for a short link. Pretty soon, you&#8217;ll be getting &#8220;Too]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=API,internet,php,server,social+networking,url-shortener&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In my last<a title="tweet this and URL shortening API" href="http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/"> tutorial</a>, I&#8217;ve touched on how to use the to.ly API and how to make automatic &#8220;Tweet it&#8221; buttons with a relevant message.<br />
Well, this can get problematic if with every page refresh, your server sends out a request to the to.ly server for a short link. Pretty soon, you&#8217;ll be getting &#8220;Too Many Connections&#8221; and you&#8217;re screwed. Just like I was, so here&#8217;s an idea. How about we store those links in a database&#8230;.automatically?</p>
<p>You see, it&#8217;s much easier to create a script that will request a shortlink, adds the link to the database, and then just call it up whenever you need it. It works perfectly well on my <a title="Only A Quote" href="http://www.onlyaquote.com">quote site</a>. Basically, whenever you create a website with get-requests, tons of pages, and all that. You can use the following script to make it all work, automatically (again).</p>
<ul>
<li><a href="#bitly">Bit.ly shortlink implementation</a></li>
<li><a href="#mysql">Adding URL Links to a MySQL database</a></li>
</ul>
<br />
<span id="more-1011"></span></p>
<h1><a name="bitly">Bit.ly</a></h1>
<p>Let&#8217;s get some bit.ly action going here. First, you need to create an account. Then you need to get the <a title="bitly API key" href="http://bit.ly/account/your_api_key">bit.ly API key</a><a rel="attachment wp-att-1012" href="http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/bitly/"><img class="aligncenter size-medium wp-image-1012" title="bitly" src="http://www.davepcguy.com/wp-content/uploads/2009/12/bitly-300x200.png" alt="" width="300" height="200" /></a>Next, let&#8217;s look at a neat <a title="bitly php script" href="http://davidwalsh.name/bitly-php">script</a> I found and made a few changes to so you could simply use include() and have a ready function with all the right variables:</p>
<pre class="brush: php; title: ;">
// Variables
$bitlylogin = 'loginname';
$apikey = 'long series of numbers that make up your API key';

/* make a URL small */
function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1')
{
 //create the URL
 $bitly = 'http://api.bit.ly/shorten?version='.$version.'&amp;longUrl='.urlencode($url).'&amp;login='.$login.'&amp;apiKey='.$appkey.'&amp;format='.$format;

 //get the url
 //could also use cURL here
 $response = file_get_contents($bitly);

 //parse depending on desired format
 if(strtolower($format) == 'json')
 {
 $json = @json_decode($response,true);
 return $json['results'][$url]['shortUrl'];
 }
 else //xml
 {
 $xml = simplexml_load_string($response);
 return 'http://bit.ly/'.$xml-&gt;results-&gt;nodeKeyVal-&gt;hash;
 }
}
</pre>
<p>I like to set my function up like this so that I can always interchange values, and so that I will automatically have the right values stored in those two variables above ($bitlylogin and $apikey). You don&#8217;t need to do that. You could simply change the function definition like to include defaults:</p>
<pre class="brush: php; title: ;">
function make_bitly_url($url,$login = 'loginusername',$appkey = 'long api key',$format = 'xml',$version = '2.0.1')
</pre>
<p>Now as far as implementation of the script goes, it&#8217;s pretty simple:</p>
<pre class="brush: php; title: ;">
$url = &quot;Http://www.davepcguy.com&quot;;
$shorturl = make_bitly_url($url, $bitlylogin, $apikey);
echo $shorturl;
</pre>
<p>And you&#8217;ll get the short url echoed out. If you use the default value version you can simply do this:</p>
<pre class="brush: php; title: ;">
$url = &quot;http://www.davepcguy.com&quot;;
$shorturl = make_ibtly_url($url);
echo $shorturl;
</pre>
<p>You&#8217;re done. Easy enough, eh?</p>
<h1><a name="mysql">MySQL Database</a></h1>
<p>Believe it, or not. It&#8217;s actually rather tricky to add a URL into a database. You have to select the correct format in the table, decode and encode stuff. It&#8217;s pretty messy and I have not found a good tutorial online on how to do this.<br />
So here goes, let&#8217;s assume you use the method above to create short links. It&#8217;ll make life much easier, trust me.</p>
<p>First, let&#8217;s create a table in your database:</p>
<pre class="brush: php; title: ;">
//login variables
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'sample database';

//connect
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!');

//database select
mysql_select_db($db) or die ('Unable to select database!');

//the right query
$query = &quot;CREATE TABLE sample_table
(
id int NOT NULL auto_increment primary key,
name varchar(50) NOT NULL,
email varchar(50) NOT NULL ,
message text NOT NULL,
url varchar(255) NOT NULL
)&quot;;

//executing query
$result = mysql_query($query) or die ('Error in Query');
</pre>
<p>Notice that I used a varchar(255) for the datatype. You could use varchar(55) or any other number. Every shortlink by bit.ly is 20 characters&#8230;max. The problem is when you add the information in your database so I recommend a good 255 characters.</p>
<p>Next, you have to make sure you know what you want out of the script. I made a script so that every time my website asked for a row of information, it would automatically add the URL (since I was a bit late with this idea, I had to find a way to add the information without having to recreate the whole database). Also, it&#8217;s a good practice to check if the data is present and in case it&#8217;s not, add it. Here&#8217;s what I did:</p>
<pre class="brush: php; title: ;">
//connect

$name = 'sample name';

//query for a particular row with the name
$query = 'SELECT * FROM sample_table WHERE name = $name'';

    // execute query
    $result = mysql_query($query) or die (&quot;Error in query: $query.&quot;.mysql_error());

//check if the url column has anything in it
if (empty($row[4])) {

//if it IS empty, let's make a shortlink
$url = make_bitly_url($permalink,$bitlylogin,$apikey,'xml');
//we have to encode the url. I'll explain that
$url = urlencode($url);
//make a query to update (don't forget the quotation marks!)
$query = 'UPDATE quotes SET url = &quot;'.$url.'&quot; WHERE name = '.$name.'';
//execute query
$urlresult = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());
//decode url for later use in the script
$url = urldecode($url);
}

//let's make an else statement in case the information IS present
else {
//let's decode that encoded url
$url = urldecode($row[4]);
}
</pre>
<p>Now you have the $url variable down! w00t. You can do a bunch of stuff with that. Like implement it in that <a title="Tweet this!" href="http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/">twitter button</a> I keep talking about. Check out my <a title="Only A Quote" href="http://www.onlyaquote.com">new site</a> too to see it in action.</p>
<p>Oh about that encoding and decoding. If you try to submit the $url without encoding it, you&#8217;ll get an error because the characters &#8220;/&#8221; and &#8220;:&#8221; and some of the other ones have a special meaning in SQL. Here&#8217;s what the encoded and decoded versions look like:</p>
<blockquote><p>normal: http://bit.ly/8oQBvB</p>
<p>encoded: http%3A%2F%2Fbit.ly%2F8oQBvB</p>
<p>decoded: http://bit.ly/8oQBvB</p></blockquote>
<p>As you can see, the encoded version uses the &#8220;%&#8221; characters (ascii) for the coding.</p>
<p>Don&#8217;t forget to encode and decode then!</p>
<p>I hope you enjoyed my tutorial <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;bodytext=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;notes=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;t=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;annotation=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;t=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;s=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>&#8220;Tweet This&#8221; and URL shortening API</title>
		<link>http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/</link>
		<comments>http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 23:00:26 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[url-shortener]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1004</guid>
		<description><![CDATA[Alright, you&#8217;ve all seen those CRAZY &#8220;Tweet This&#8221; buttons on so many websites, (mainly wordpress). You may have also noticed that some just send you to twitter and you have to manually input the twitter message. Well, how about we just make a button that will automate all this for us? I really do love]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=functions,php,server,social+networking,twitter,url-shortener&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Alright, you&#8217;ve all seen those CRAZY &#8220;Tweet This&#8221; buttons on so many websites, (mainly wordpress). You may have also noticed that some just send you to twitter and you have to manually input the twitter message. Well, how about we just make a button that will automate all this for us?</p>
<p>I really do love it when I click on that button and twitter pops up with a pre-written message like &#8220;Check out this site : URL GOES HERE&#8221; or &#8220;Crazy CSS tutorial on backgrounds. Check it out: URL GOES HERE&#8221;, it makes it much easier for me to share my finds. Here&#8217;s a great <a title="Only A Quote" href="http://www.onlyaquote.com">demo</a>.</p>
<p>Okay, I&#8217;m working on a new website and it has various posts on it that I want the readers to be able to automatically share on twitter. I also want to include a backlink so that their twitter followers can visit the actual article. Basically, here&#8217;s a tutorial on shortening URLs using API and for creating a twitter button.</p>
<p><span id="more-1004"></span><br />
</p>
<h2>URL shortening</h2>
<p>As you may know, there are tons of <a title="comparing short links" href="http://www.davepcguy.com/archive/comparing-short-links/">URL shortening services</a>. Most, including<a title="bit.ly" href="http://www.bit.ly"> bit.ly</a> and<a title="tiny url " href="http://www.tinyurl.com"> tinyurl.com</a> support API services which basically means, you can use PHP (and AJAX) in order to use their services on another server. That&#8217;s BASICALLY what it means. I&#8217;m not a master of this. Bit.ly requires an account so I won&#8217;t be getting into that. I don&#8217;t want my account to be spammed with a ton of different links. But, if you want to keep track of how many people clicked and posted your link, you are more than welcome to read a tutorial on it <a title="bitly php api" href="http://davidwalsh.name/bitly-php">elsewhere</a>.</p>
<p>I&#8217;m not too big on tinyurl.com anymore because it requires way too many characters. And for twitter use, it&#8217;s basically useless so I browsed around and found <a title="to.ly shrinking URLs" href="http://to.ly">to.ly</a> which has really basic API info already <a title="to.ly api info" href="http://to.ly/api_info.php">posted</a>. Let me copy it real quick:</p>
<pre class="brush: php; title: ;">
function CompressURL($url) {

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, &quot;http://to.ly/api.php?longurl=&quot;.urlencode($url));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HEADER, 0);

  $shorturl = curl_exec ($ch);
  curl_close ($ch);

  return $shorturl;

}
</pre>
<p>Add this function to your function.php, if you use an external function list (use require() to add it to your site), or just add this function in your header on your site so that whenever you call upon it later, it will be at your disposal. Now, let&#8217;s get the URL of the site you&#8217;re on. Let&#8217;s say you have a dynamic page and don&#8217;t feel like manually writing each separate link. We can use the $_SERVER variable for that. A combination actually:</p>
<pre class="brush: php; title: ;">
echo &quot;http://&quot;.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
</pre>
<p>This will echo out the whole URL, including any GET statements you may have entered. If you don&#8217;t want those statements, erase the last $_SERVER variable. Okay, so let&#8217;s put it all together to shorten the link using the previous function:</p>
<pre class="brush: php; title: ;">
$permalink = &quot;http://&quot;.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
$url = CompressURL (&quot;$permalink&quot;);
</pre>
<p>Now that we have the compressed URL, let&#8217;s move on to the tweet button.</p>
<h2>Tweet This Button!</h2>
<p>Well, go out and find some great twitter icon. Or make your own. It&#8217;s easy. You go into photoshop and make a 150 x 50 px rectangle and write twitter in it. That&#8217;s not what this tutorial is about.<br />
Twitter has an easy-to-use API (Is it even API?).</p>
<pre class="brush: xml; title: ;">
http://twitter.com/home?status= MESSAGE GOES HERE
</pre>
<p>So there goes the message. Very easy, no? Now, here lies the problem. What kind of message do you want? You could use different functions and variables that describe each page on your site. If you set them manually (in the META tag), use this instead so that the description is already stored for later use. In my <a title="Only A Quote" href="http://www.onlyaquote.com">newest site</a>, I used the actual content of the page (a quote) for the message:</p>
<pre class="brush: php; title: ;">
$description = &quot;An article about php scripting and creating a simple tweet this button.&quot;;
echo $description
</pre>
<p>Twitter has a character limit of one forty, right? We can take care of that too. &#8220;substr()&#8221; is a function that will allow you to cut up your description. It works like this: substr($string, begin cut, end cut). I use a 100 character cut off:</p>
<pre class="brush: php; title: ;">

$twittermsg = substr($description, 0, 100);

$twittermsg .= &quot;...more on&quot;.$url;
</pre>
<p>The message is complete. A hundred character message ending with &#8220;&#8230;more on URL&#8221;. Finally, the button and link:</p>
<pre class="brush: xml; title: ;">
&lt;a href=&quot;http://twitter.com/home?status=&lt;?php echo $twittermsg;?&gt;&quot; target=&quot;_blank&quot;&gt; &lt;img src=&quot;pictures/images/twitter_button.png&quot; title=&quot;Tweet it!&quot; onmouseover=&quot;this.src='pictures/images/twitter_button_hover.png'&quot;
onmouseout=&quot;this.src='pictures/images/twitter_button.png'&quot; /&gt;&lt;/a&gt;
</pre>
<p>The &#8220;onmouseover&#8221; and &#8220;onmouseout&#8221; are used for a nice hover effect (onmouseover will be the hoveved, and onmouseout is the non-hovered). Using CSS would be a literal pain because you&#8217;d have to create a clickable div or a span&#8230;display none. Well, just trust me, this is MUCH easier.</p>
<p>I hope you enjoyed this short tutorial!</p>
<p><strong>Check out my next <a title="Bit.ly API" href="http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/">tutorial</a> for bit.ly API! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong><br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;bodytext=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;notes=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;t=%22Tweet%20This%22%20and%20URL%20shortening%20API" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;annotation=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;t=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;s=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%22Tweet%20This%22%20and%20URL%20shortening%20API%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Custom E-mail Form</title>
		<link>http://www.davepcguy.com/archive/custom-e-mail-form/</link>
		<comments>http://www.davepcguy.com/archive/custom-e-mail-form/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 19:14:43 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[coupon]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web extras]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=557</guid>
		<description><![CDATA[AH! So I have to create a custom e-mail sending form. He wants me to create a webform that will ask for a person&#8217;s name and e-mail address. Once those are input, an e-mail will be sent to the person&#8217;s e-mail account with a thank you message. Meanwhile, the website will reload with a custom]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=coupon,functions,mail,php,web+extras&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>AH! So I have to create a custom e-mail sending form. He wants me to create a webform that will ask for a person&#8217;s name and e-mail address. Once those are input, an e-mail will be sent to the person&#8217;s e-mail account with a thank you message. Meanwhile, the website will reload with a custom coupon that bears their name. I&#8217;ll need it printable so I&#8217;ll have to add a print button as well.<br />
Sounds simple enough, right?.. right?<br />
<span id="more-557"></span><br />
First off, go <a title="coupon tutorial" href="http://www.davepcguy.com/archive/coupon-design/">create a coupon</a>. After you&#8217;re done with that, we can start working. Make sure the &#8220;name&#8221; field is left out though, we&#8217;ll add that in later with some CSS. Originally, I wanted to send the coupon in the e-mail, forcing the customer to input the right e-mail address but I realized that most e-mail clients do not support CSS and especially not the &#8220;position: absolute;&#8221; property and value.<br />
<br />
<strong>Tip</strong>: I update the script periodically, and have numerous times while writing this tutorial. None of the scripts mentioned in this post are necessarily WRONG but at the bottom of the page is the current &#8220;release&#8221; that I&#8217;ve created. The images may not correspond directly with the code they represent.</p>
<h1>Setup</h1>
<p>Alright, here&#8217;s what you&#8217;ll need to do. You need to download MIME (MultiplePurpose Internet Mail Extensions), which is an e-mail extension for php that allows you to send HTML e-mails. If your site operates under c-panel, like mine is, then just scroll down, find the PHP extension icon. Search for &#8220;MIME&#8221; and install the packages. If you need to install them manually, search through google &#8220;Installing MIME on&#8221; your OS. I cannot really help you out more than that because I am not an expert on PHP extensions. There are multiple guides online though that WILL help you out.</p>
<div id="attachment_632" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/mail1.png"><img class="size-medium wp-image-632" title="mail1" src="http://www.davepcguy.com/wp-content/uploads/2009/10/mail1-300x105.png" alt="installing MIME" width="300" height="105" /></a><p class="wp-caption-text">installing MIME</p></div>
<div id="attachment_633" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/mail2.png"><img class="size-medium wp-image-633" title="mail2" src="http://www.davepcguy.com/wp-content/uploads/2009/10/mail2-300x54.png" alt="Press Install" width="300" height="54" /></a><p class="wp-caption-text">Press Install</p></div>
<p>Once you press install, the package will automatically install. It may ask if it can install other dependent packages, simply OK it.</p>
<h1>Basic Form</h1>
<div id="attachment_634" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/mail3.png"><img class="size-medium wp-image-634" title="mail3" src="http://www.davepcguy.com/wp-content/uploads/2009/10/mail3-300x185.png" alt="Modified Mail Form" width="300" height="185" /></a><p class="wp-caption-text">Modified Mail Form</p></div>
<p>Let&#8217;s start scripting. I advise you to create a mail.php form that you can &#8220;include ()&#8221; or &#8220;require()&#8221; into your existing website. It&#8217;s much neater this way and the PHP won&#8217;t get in the way of your layout. Here&#8217;s the basic form I created for our purposes:</p>
<pre class="brush: xml; title: ;">&lt;form action=&quot;&lt;?php $_SERVER['PHP_SELF'];?&gt;&quot; method=&quot;post&quot;&gt;
Name:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; maxlength=&quot;41&quot; /&gt;&lt;br /&gt;
E-mail address:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;email&quot; maxlength=&quot;40&quot; /&gt;&lt;br /&gt;
Message (&lt;i&gt;optional&lt;/i&gt;):&lt;br /&gt; &lt;textarea name=&quot;optmessage&quot; cols=&quot;30&quot; rows&quot;10&quot; maxlength&quot;140&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;save&quot; /&gt;
&lt;/form&gt;</pre>
<p>I used the &#8220;$_SERVER['PHP_SELF']&#8221; variable for the action so that we won&#8217;t have to create yet another script page to use the information. The &#8220;name&#8221; field will translate to $_POST['name'], the&#8221;e-mail address&#8221; into $_POST['email'], and the optional &#8220;message&#8221; into $_POST['optmessage']. There is nothing much more to it. I used maxlength for the name 41 characters because my full fictional name, &#8220;Captain Soren William Alexander Janus VI.&#8221;, is exactly 41 characters long .  40 characters for the e-mail seems sufficient enough as well. 140 character message is the same as twitter&#8217;s max tweet. There is nothing much else to this.</p>
<h1>Are you feeling &#8220;Loopy&#8221;?</h1>
<p>Let&#8217;s move on. We need to create a loop that will ensure our data has been entered and that we are not dealing with a blank form. The purpose of this basic loop is to show the initial form for the user to submit the data to, reload the form if any errors were made during submission (ie invalid entries), and send the email in the end.</p>
<pre class="brush: php; title: ;">
&lt;?php
if (!isset($_POST['submit']) { ?&gt;

Form goes here

&lt;?php } elseif (empty($_POST['email']) || empty($_POST['name']) ||
(isEmailAddress($_POST['email']) == 0) || (trim($_POST['email']) == '')
|| (trim($_POST['name']) == '')) {
?&gt;

Something entered was wrong, please re-enter your information:
form goes here.

&lt;?php }
else {
store variables, send e-mail, and show a new page with a coupon }
?&gt;
</pre>
<p>Confused? Don&#8217;t be. The beginning tells us if the form has been previously submitted, if not, the form will load. The second part after &#8220;elseif&#8221; checks if all the data entered is correct. After all the conditions have been met, we progress to the last &#8220;else&#8221; which will execute the mail sending.</p>
<h1>&#8220;Validate This!&#8221;</h1>
<p>If you look above, you&#8217;ll see a strange function called &#8220;isEmailAddress&#8221;. I set this function up using a script I <a title="validation scripts" href="http://devzone.zend.com/node/view/id/662">found</a>. Here is the function:</p>
<pre class="brush: php; title: ;">
function isEmailAddress($value) {
        return eregi('^([a-z0-9])+([\.a-z0-9_-])*@([a-z0-9_-])+(\.[a-z0-9_-]+)*\.([a-z]{2,6})$', $value);
    }
	</pre>
<p>It basically checks if the e-mail is in the correct format. It also makes sure that only a single e-mail address has been entered and that it does not contain any malicious code.</p>
<p><strong>Tip</strong>: If you wish to add database support to this script, you&#8217;ll have to use a validation function for the name and message as well!</p>
<p>Next part of validation are the &#8220;empty()&#8221; and &#8220;trim()&#8221; functions. &#8220;Empty()&#8221; is self-explanatory. You entered the variable name and the function will check if it is empty or not. If it is, the function returns TRUE. &#8220;Trim()&#8221; works similarly except here it takes out all the extra spaces and such. If it equals &#8216; &#8216; or an empty space, then it will return TRUE. The &#8220;elseif&#8221; statement is setup so that it checks the e-mail and name value.</p>
<p><strong>Tip: </strong>If you have some time on your hand you can create a function that will check for each of these statements like: function CheckValue ($var) { if (empty($var) {return TRUE;} if (trim($var) == &#8216; &#8216;) { return TRUE;} }</p>
<h1>Second Form</h1>
<div id="attachment_635" class="wp-caption aligncenter" style="width: 302px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/mail4.png"><img class="size-full wp-image-635" title="mail4" src="http://www.davepcguy.com/wp-content/uploads/2009/10/mail4.png" alt="Incorrect entry" width="292" height="265" /></a><p class="wp-caption-text">Incorrect entry</p></div>
<p>You have a choice here. Under &#8220;elseif ()&#8221;, you can create new &#8220;if&#8221; statements and inform the user of what exactly is wrong. For example if the name is empty, you can create an if statement like this:</p>
<pre class="brush: php; title: ;">
if (empty($_POST['name'] || trim($_POST['name']) == ' ') { ?&gt;
 echo &quot;You left the name field empty&quot;;
&lt;?php } ?&gt;
</pre>
<p>I like to keep the user in the shadows and put all of the validation together using the || which means &#8220;or&#8221; and the same original form will show up with the message &#8220;Error: Please enter a valid e-mail address and your name&#8221;. Add the following form under &#8220;elseif()&#8221; between the php tags:</p>
<pre class="brush: xml; title: ;">
Error: Please enter a valid e-mail address and your name

&lt;form action=&quot;&lt;?php $_SERVER['PHP_SELF'];?&gt;&quot; method=&quot;post&quot;&gt;
Name:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; maxlength=&quot;41&quot; /&gt;&lt;br /&gt;
E-mail address:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;email&quot; maxlength=&quot;40&quot; /&gt;&lt;br /&gt;
Message (&lt;i&gt;optional&lt;/i&gt;):&lt;br /&gt; &lt;textarea name=&quot;optmessage&quot; cols=&quot;30&quot; rows&quot;10&quot; maxlength&quot;140&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>It&#8217;s the same form with a little message on top.</p>
<h1>Everything &#8220;Else&#8221;</h1>
<p>So all the variables go through, the script is validated. What now then? Now we&#8217;ll send the e-mail and refresh the site. I am using e-mails for a good reason. Whenever a user asks for a coupon, I&#8217;ll have a copy of their name and their e-mail address for future reference. I COULD use a database system but I&#8217;m a lazy person. I&#8217;ll point you in the right direction if you wish to do that though. Instead, let&#8217;s focus on what I already have done.</p>
<p>We should set up our variables first, writing out $_POST['email'] is quite a hassle. Plus, we have to set up the e-mail variables as well. Also note that this is in the last else {} section:</p>
<pre class="brush: php; title: ;">
//variables

$to = $_POST['email'];
$subject = &quot;Coupon from the Chiropractors&quot;;
$name = $_POST['name'];
$optmessage= $_POST['optmessage'];
$opt = wordwrap ($optmessage, 70);
</pre>
<p>The mail function works like this:</p>
<blockquote><p>mail (to, subject, message, headers)</p></blockquote>
<p>So we set up the &#8220;$to&#8221; variable which we will direct to the e-mail. We&#8217;ve also set up the subject of the e-mail and put $_POST['name'] into the $name variable for later use. Next, I transferred the optional message into $optmessage variable which I then word-wrapped into $opt. You have to word-wrap your e-mail message and the longest line can only have 70 characters. Using the &#8220;wordwrap ()&#8221; function and the parameter &#8220;70&#8243;, we&#8217;ve accomplished that. Let&#8217;s write the message:</p>
<pre class="brush: php; title: ;">
$message = &quot;&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=\&quot;Content-Type\&quot; content=\&quot;text/html; charset=utf-8\&quot; /&gt;
&lt;title&gt;Chiropractic&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt; Dear $name,&lt;br /&gt;
Thank you for visiting us at our&lt;a href=\&quot;http://www.davepcguy.com\&quot;&gt;Website&lt;/a&gt;.
&lt;p&gt; Please print out your coupon and present it on your next visit. Thank you, and we hope to see you soon!&lt;/p&gt;
&lt;p style=\&quot;margin-left: 50px\&quot;&gt; Sincerely, Alexander &lt;/p&gt;
&lt;p&gt;optional message:&lt;br /&gt;
$opt&lt;/p&gt;
&lt;p&gt;
Your e-mail: $to &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;&quot;;
</pre>
<p>Note that e-mail clients have different <a title="CSS support for different e-mail clients" href="http://www.campaignmonitor.com/css/">support</a> of HTML and CSS. Don&#8217;t include any XHTML, that&#8217;s way too complicated. This is the reason why I did not put the coupon into the e-mail. Most e-mail clients do not support the &#8220;position: absolute&#8221;. Alright, let&#8217;s setup our header variable. With headers, you can define who the e-mail is from, where to reply to the e-mail, send different copies, and most importantly, use MIME.</p>
<pre class="brush: php; title: ;">
 //header information
$from = &quot;no-reply@davepcguy.com&quot;;
$headers = &quot;From: $from&quot; . &quot;\r\n&quot;;
$headers .= 'MIME-Version: 1.5.2' . &quot;\r\n&quot;;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . &quot;\r\n&quot;;
$headers .= &quot;BCC: reply@davepcguy.com&quot; . &quot;\r\n&quot;;
</pre>
<p>I used an e-mail address I set up through c-panel. Set it up the same way you set up any other e-mail account. And you won&#8217;t even have to include the password in your script. Let&#8217;s break down the header.</p>
<p>The first header establishes from where the e-mail will be sent. Always break the lines when setting up the header variable using &#8220;\r\n&#8221;. Next, set up your MIME and its version. The newest one should be 1.5.2 but check your version under the PHP addons/modules in your c-panel. If you can&#8217;t make it work, use &#8220;MIME-Version: 1.0&#8243;. Next, set the content-type. Just copy the above, there should be no other alternative. The script will also send a BCC (Blind Carbon Copy) of every e-mail to my own e-mail address so that I can keep records. Let&#8217;s send it then!</p>
<pre class="brush: php; title: ;">
//functions
$mail_sent= mail(&quot;$to&quot;, $subject, $message, $headers);
</pre>
<p>All that work and it&#8217;s summed up in one single line, amazing, eh?</p>
<h1>The Script After</h1>
<p>Hmm&#8230;I think I should give the user the coupon finally, don&#8217;t you think? They&#8217;ve done SO much work. Well, let me set up the message then:</p>
<pre class="brush: php; title: ;">
//announcement
$sent= &quot;
&lt;p&gt; Dear $name,&lt;br /&gt;
Thank you for visiting us at &lt;a href=\&quot;http://www.davepcguy.com\&quot;&gt;Website&lt;/a&gt;
Here is your coupon&lt;/p&gt;
&lt;div align=\&quot;center\&quot; style=\&quot;padding=\&quot;50px\&quot;&gt;
&lt;div style=\&quot;position: absolute; margin: 75px 120px 10px 50px; font-size: 30px; border-bottom: 2px solid black; width: 250px\&quot;&gt; $name &lt;/div&gt;
&lt;img src=\&quot;coupon2.png\&quot; width=\&quot;436\&quot; height=\&quot;292\&quot; /&gt;&lt;/div&gt;
&lt;p&gt; Please print this coupon out and present it on your next visit. Thank you, and we hope to see you soon!&lt;/p&gt;
&lt;p style=\&quot;margin-left: 50px\&quot;&gt; Sincerely, Alexander &lt;/p&gt;
&lt;p&gt; P.S. please print out your coupon immediately or save this page because it will not be available after you close out.
If you're having any trouble, please contact our &lt;a href=\&quot;mailto:alexander@davepcguy.com\&quot;&gt;webmaster&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Optional Message: &lt;br /&gt;
$opt
&lt;/p&gt;
&quot;;
echo $mail_sent ? $sent : &quot;Mail failed&quot;;
echo $sent;
}
?&gt;
</pre>
<p>Haha, I know, it looks complicated, doesn&#8217;t it? Well not really, the &#8220;$sent&#8221; just sets up a variable with the html code I plan to use in my webpage. Beware, you&#8217;ll have to adjust this according to your own webpage. the echo $mail_sent ? $sent: &#8220;Mail failed&#8221;; is a short hand for an if loop &#8221; if ($mail_sent) {$sent} else { &#8220;Mail Failed&#8221;};&#8221; then the $sent variable will echo out.</p>
<div id="attachment_636" class="wp-caption aligncenter" style="width: 280px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/mail5.png"><img class="size-medium wp-image-636" title="mail5" src="http://www.davepcguy.com/wp-content/uploads/2009/10/mail5-270x300.png" alt="final page" width="270" height="300" /></a><p class="wp-caption-text">final page</p></div>
<h1>Extras</h1>
<ul>
<li>database support</li>
<li>print</li>
<li>extra validation</li>
</ul>
<p>This is how I finished out my script. I don&#8217;t plan on doing too much to it other than making it printable. I&#8217;m thinking about making a pop-up window that will display all of that information. Let&#8217;s review some of the extras you can add.</p>
<p><strong>Database Support </strong>First, you can add database support. Simply make a new database in MySQL (using PHPmyAdmin) and set up two columns, one for name, and the other for name. Set up the table or use this SQL command if you can, creating the database might be tricky, but you should be able to use the &#8220;CREATE TABLE&#8221; part. If you can&#8217;t, just set it up manually using the values shown:</p>
<pre>CREATE DATABASE coupondb;

CREATE TABLE `coupons` (
    `id` int(11) NOT NULL auto_increment,
    `name` varchar(255) NOT NULL default '',
    `email` varchar(255) NOT NULL default '',
    PRIMARY KEY  (`id`)
) TYPE=MyISAM;</pre>
<p>You can probably make a third column for an order (1., 2., 3.) or for the date and time. Add this at the beginning of the &#8220;else{}&#8221; :</p>
<pre class="brush: php; title: ;">
//MySQL variable
$host = &quot;localhost&quot;;
$user = &quot;user&quot;;
$pass = &quot;password&quot;;
$db = &quot;coupondb&quot;;

//connect
$connection = mysql_connect($host, $user, $pass) or die (&quot;Unable to connect!&quot;);

// select database
mysql_select_db($db) or die (&quot;Unable to select database!&quot;);
</pre>
<p>First, set up the host variable ie, where the database is. I&#8217;ll trust my WordPress senses and leave that with localhost. You&#8217;ll have to create a new username and password as well as a database manually using c-panel or a different site manager your hosting provides you. Input the user and password. Change the &#8220;die&#8221; variable to something like &#8220;internal server error&#8221; or something, this is just for educational purposes. I got it off <a title="Database Tutorial Zend" href="http://devzone.zend.com/node/view/id/641">Zend Dev Zone </a>again. Make sure you put this BEFORE the e-mail sending (ie the mail() function) because it&#8217;s senseless to send the e-mail but not make a database entry. Here&#8217;s the basic query:</p>
<pre class="brush: php; title: ;">
 // create query
    $query = &quot;INSERT INTO coupons (name, email) VALUES ('$name', '$to')&quot;;

    // execute query
    $result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());

    // close connection
    mysql_close($connection);
</pre>
<p>And there you go, database support added. Check out my full script on the bottom for the full implementation with the duplicate entries check as well as other features.</p>
<p><strong>Print </strong><img src="file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/moz-screenshot.png" alt="" />Let&#8217;s check out how to print all this stuff out. I found a neat piece of JavaScript that can accomplish this. It&#8217;s a bit tricky and I still can&#8217;t get it to show the best results but, it seems to work well nonetheless. You can find it <a title="javascript print code" href="http://personalweb.about.com/od/copypastejavascripts/a/404_3scripts_3.htm">here</a>. Add the header part into the real header where you&#8217;ll use this mail.php script. Then, modify the $sent variable:</p>
<pre class="brush: php; title: ;">
$sent= &quot;&lt;div id=\&quot;printReady\&quot;&gt;
&lt;div style=\&quot; width: 457px; background: white; text-align: center\&quot;&gt;
&lt;p&gt; Dear $name,&lt;br /&gt;
Thank you for visiting us at &lt;a href=\&quot;http://www.davepcguy.com\&quot;&gt;Website&lt;/a&gt;
Here is your coupon&lt;/p&gt;
&lt;div align=\&quot;center\&quot; style=\&quot;padding=\&quot;50px\&quot;&gt;
&lt;div style=\&quot;position: absolute; margin: 75px 120px 10px 50px; font-size: 30px; border-bottom: 2px solid black; width: 250px\&quot;&gt; $name &lt;/div&gt;
&lt;img src=\&quot;coupon2.png\&quot; width=\&quot;436\&quot; height=\&quot;292\&quot; /&gt;&lt;/div&gt;
&lt;p&gt; Please print this coupon out and present it on your next visit. Thank you, and we hope to see you soon!&lt;/p&gt;
&lt;p style=\&quot;margin-left: 50px\&quot;&gt; Sincerely, Alexander &lt;/p&gt;
&lt;p&gt; P.S. please print out your coupon immediately or save this page because it will not be available after you close out.
If you're having any trouble, please contact our &lt;a href=\&quot;mailto:alexander@davepcguy.com\&quot;&gt;webmaster&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Optional Message: &lt;br /&gt;
$opt
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;
&lt;form id=\&quot;printMe\&quot; name=\&quot;printMe\&quot;&gt;  &lt;input type=\&quot;button\&quot; name=\&quot;printMe\&quot; onClick=\&quot;printSpecial()\&quot; value=\&quot;Print this Page\&quot;&gt; &lt;/form&gt;
&quot;;</pre>
<p>Change the width to suit your needs. And I am completely aware there is a million different divs just in this script (you should see the pages I code, million more divs) but they are mostly mandatory. You can switch the &#8220;div&#8221; around the &#8220;$name&#8221; variable to &lt;span&gt;. You&#8217;ll have to spend some time adjusting this, the width of the page, the margin, as well as the different positions to suit your needs. It worked for me almost perfectly <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Extra Validation</strong> Okay, so if you want to use a database with this form, you&#8217;ll need some extra validation as a precaution against SQL injection. We&#8217;ve already validated the e-mail address and I won&#8217;t be validating the optional message just yet. So let&#8217;s validate the name. I used a function from the same script I cited when I used the e-mail validation function:</p>
<pre class="brush: php; title: ;">
// check whether input is alphabetic
    function isAlpha($value) {
        return preg_match('/^[a-zA-Z]+$/', $value);
    }
</pre>
<p>Add this function to the beginning of the document and add another || to the elseif () {} part of the loop saying &#8220;!isAlpha($_POST['name'])&#8221;. Also, warn the user that they can use only letters for the name and no periods or other characters nor numbers. The optional message SHOULD be validated but I am not certain how to go about it just yet. I&#8217;d like to let the user be able to use some personalized html code so I won&#8217;t look into it too much. Also, I am not storing that message so I don&#8217;t have to fear an SQL attack.</p>
<h1>Conclusion</h1>
<p>I hope this shed some light on how you&#8217;d create an e-mail form as well as how to use the mail() function. As you can see, the possibilities with PHP are endless. I&#8217;d like to also inform you that it took me several hours to write this script with numerous trial&amp;error runs. I&#8217;m self-taught, and mostly used the <a title="PHP manual" href="http://php.net/manual/en/index.php">PHP manual</a> as a reference. I hope this helped and that you have fun trying this out for yourselves!</p>
<p>I&#8217;d appreciate any comments regarding the security of this script as well as usability. I, myself, am about to launch the script on one of my pages so I&#8217;d like to know what people have to say about it.</p>
<p>Final Script with all its features added: Note that I will update this part of the post as necessary when I find bugs and optimize it.</p>
<pre class="brush: php; title: ;">

&lt;?php
//functions
/* PHP script written by Alexander Janus
contact: alexander@davepcguy.com
blog: http://www.davepcguy.com
if you want to use this script, include this header
*/
function isEmailAddress($value) {
 return eregi('^([a-z0-9])+([\.a-z0-9_-])*@([a-z0-9_-])+(\.[a-z0-9_-]+)*\.([a-z]{2,6})$', $value);
 }
// check whether input is alphabetic
function isAlpha($value) {
 return preg_match('/^[a-zA-Z]+$/', $value);
 }

function name ($var) {
 if (!isset($var)){
 return TRUE;
 }
 if (empty($var)){
 return TRUE;
 }
 if (trim($var) == ''){
 return TRUE;
 }
 if (isAlpha($var) == 0){
 return TRUE;
 }
}
function email ($var) {
 if (!isset($var)){
 return TRUE;
 }
 if (empty($var)){
 return TRUE;
 }
 if (trim($var) == ''){
 return TRUE;
 }
 if (isEmailAddress($var) == 0){
 return TRUE;
 }
}

//loop
if(!isset($_POST['submit'])){

 ?&gt;
Please enter your name and e-mail address. The name field supports only alphabetic characters (letters).
&lt;form action=&quot;&lt;?php $_SERVER['PHP_SELF'];?&gt;&quot; method=&quot;post&quot;&gt;
Name:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; maxlength=&quot;41&quot; /&gt;&lt;br /&gt;
E-mail address:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;email&quot; maxlength=&quot;40&quot; /&gt;&lt;br /&gt;
Message (&lt;i&gt;optional&lt;/i&gt;):&lt;br /&gt; &lt;textarea name=&quot;optmessage&quot; cols=&quot;30&quot; rows&quot;10&quot; maxlength&quot;140&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;

&lt;?php
}

elseif (name($_POST['name']) || email($_POST['email'])) {
 if (name($_POST['name'])) {
 echo &quot;Please enter a valid name. Periods, commas, or other non-alpha characters are not supported.&lt;br/&gt;&quot;;
 }
 if (email($_POST['email'])){
 echo &quot;Please enter a valid e-mail address in this format: account@email.com. &lt;br /&gt;&quot;;}
?&gt;

&lt;form action=&quot;&lt;?php $_SERVER['PHP_SELF'];?&gt;&quot; method=&quot;post&quot;&gt;
Name:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; maxlength=&quot;41&quot; /&gt;&lt;br /&gt;
E-mail address:&lt;br /&gt; &lt;input type=&quot;text&quot; name=&quot;email&quot; maxlength=&quot;40&quot; /&gt;&lt;br /&gt;
Message (&lt;i&gt;optional&lt;/i&gt;):&lt;br /&gt; &lt;textarea name=&quot;optmessage&quot; cols=&quot;30&quot; rows&quot;10&quot; maxlength&quot;140&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;
 &lt;?php

}
else {
//Database connection
//MySQL variable
$host = &quot;localhost&quot;;
$user = &quot;user&quot;;
$pass = &quot;password&quot;;
$db = &quot;coupon&quot;;

//connect
$connection = mysql_connect($host, $user, $pass) or die (&quot;Unable to connect!&quot;);

// select database
mysql_select_db($db) or die (&quot;Unable to select database!&quot;);

//variables

$to = $_POST['email'];
$subject = &quot;Coupon from the Chiropractors&quot;;
$name = $_POST['name'];
$optmessage= $_POST['optmessage'];
$opt = wordwrap ($optmessage, 70);
$sent= &quot;&lt;div id=\&quot;printReady\&quot;&gt;
&lt;div style=\&quot; width: 457px; background: white; text-align: center;\&quot;&gt;
&lt;p&gt; Dear $name,&lt;br /&gt;
Thank you for visiting us at &lt;a href=\&quot;http://www.davepcguy.com\&quot;&gt;Website&lt;/a&gt;
Here is your coupon&lt;/p&gt;
&lt;div align=\&quot;center\&quot; style=\&quot;padding=\&quot;50px\&quot;&gt;
&lt;span style=\&quot;position: absolute; margin: 75px 120px 10px 50px; font-size: 30px; border-bottom: 2px solid black; width: 250px\&quot;&gt; $name &lt;/span&gt;
&lt;img src=\&quot;coupon2.png\&quot; width=\&quot;436\&quot; height=\&quot;292\&quot; /&gt;&lt;/div&gt;
&lt;p&gt; Please print this coupon out and present it on your next visit. Thank you, and we hope to see you soon!&lt;/p&gt;
&lt;p style=\&quot;margin-left: 50px\&quot;&gt; Sincerely, Alexander &lt;/p&gt;
&lt;p&gt; P.S. please print out your coupon immediately or save this page because it will not be available after you close out.
If you're having any trouble, please contact our &lt;a href=\&quot;mailto:alexander@davepcguy.com\&quot;&gt;webmaster&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Optional Message: &lt;br /&gt;
$opt
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;
&lt;form id=\&quot;printMe\&quot; name=\&quot;printMe\&quot;&gt;  &lt;input type=\&quot;button\&quot; name=\&quot;printMe\&quot; onClick=\&quot;printSpecial()\&quot; value=\&quot;Print this Page\&quot;&gt; &lt;/form&gt;
&quot;;

//MYSQL QUERY
//check for duplicates
$duplicate = mysql_query(&quot;SELECT * FROM coupons where email='$to'&quot;);
$affected_rows = mysql_num_rows($duplicate);
if($affected_rows &gt;= 1)
{
echo $sent;
echo &quot;&lt;span style=\&quot;color: red;\&quot;&gt;Note: If you have already entered your e-mail address before, you will not get another e-mail message. &lt;br /&gt;
This is to prevent spamming.&lt;/span&gt;&quot;;
die('');
}
else {
// create query
 $query = &quot;INSERT INTO coupons (name, email) VALUES ('$name', '$to')&quot;;

 // execute query
 $result = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());

 // close connection
 mysql_close($connection);

}

//html message
$message = &quot;&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=\&quot;Content-Type\&quot; content=\&quot;text/html; charset=utf-8\&quot; /&gt;
&lt;title&gt;Chiropractic&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt; Dear $name,&lt;br /&gt;
Thank you for visiting us at our&lt;a href=\&quot;http://www.davepcguy.com\&quot;&gt;Website&lt;/a&gt;
&lt;p&gt; Please print out your coupon and present it on your next visit. Thank you, and we hope to see you soon!&lt;/p&gt;
&lt;p style=\&quot;margin-left: 50px\&quot;&gt; Sincerely, Alexander &lt;/p&gt;
&lt;p&gt;optional message:&lt;br /&gt;
$opt&lt;/p&gt;
&lt;p&gt;
Your e-mail: $to &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;&quot;;

 //header information
$from = &quot;no-reply@davepcguy.com&quot;;
$headers = &quot;From: $from&quot; . &quot;\r\n&quot;;
$headers .= 'MIME-Version: 1.5.2' . &quot;\r\n&quot;;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . &quot;\r\n&quot;;
$headers .= &quot;BCC: reply@davepcguy.com&quot; . &quot;\r\n&quot;;

//functions
$mail_sent= mail(&quot;$to&quot;, $subject, $message, $headers);

//announcement

echo $mail_sent ? $sent : &quot;Mail failed&quot;;
echo $sent;
}

?&gt;
</pre>




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;title=Custom%20E-mail%20Form&amp;bodytext=AH%21%20So%20I%20have%20to%20create%20a%20custom%20e-mail%20sending%20form.%20He%20wants%20me%20to%20create%20a%20webform%20that%20will%20ask%20for%20a%20person%27s%20name%20and%20e-mail%20address.%20Once%20those%20are%20input%2C%20an%20e-mail%20will%20be%20sent%20to%20the%20person%27s%20e-mail%20account%20with%20a%20thank%20you%20message.%20Meanwhil" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;title=Custom%20E-mail%20Form&amp;notes=AH%21%20So%20I%20have%20to%20create%20a%20custom%20e-mail%20sending%20form.%20He%20wants%20me%20to%20create%20a%20webform%20that%20will%20ask%20for%20a%20person%27s%20name%20and%20e-mail%20address.%20Once%20those%20are%20input%2C%20an%20e-mail%20will%20be%20sent%20to%20the%20person%27s%20e-mail%20account%20with%20a%20thank%20you%20message.%20Meanwhil" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;t=Custom%20E-mail%20Form" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;title=Custom%20E-mail%20Form&amp;annotation=AH%21%20So%20I%20have%20to%20create%20a%20custom%20e-mail%20sending%20form.%20He%20wants%20me%20to%20create%20a%20webform%20that%20will%20ask%20for%20a%20person%27s%20name%20and%20e-mail%20address.%20Once%20those%20are%20input%2C%20an%20e-mail%20will%20be%20sent%20to%20the%20person%27s%20e-mail%20account%20with%20a%20thank%20you%20message.%20Meanwhil" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;title=Custom%20E-mail%20Form&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=AH%21%20So%20I%20have%20to%20create%20a%20custom%20e-mail%20sending%20form.%20He%20wants%20me%20to%20create%20a%20webform%20that%20will%20ask%20for%20a%20person%27s%20name%20and%20e-mail%20address.%20Once%20those%20are%20input%2C%20an%20e-mail%20will%20be%20sent%20to%20the%20person%27s%20e-mail%20account%20with%20a%20thank%20you%20message.%20Meanwhil" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;title=Custom%20E-mail%20Form" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;t=Custom%20E-mail%20Form&amp;s=AH%21%20So%20I%20have%20to%20create%20a%20custom%20e-mail%20sending%20form.%20He%20wants%20me%20to%20create%20a%20webform%20that%20will%20ask%20for%20a%20person%27s%20name%20and%20e-mail%20address.%20Once%20those%20are%20input%2C%20an%20e-mail%20will%20be%20sent%20to%20the%20person%27s%20e-mail%20account%20with%20a%20thank%20you%20message.%20Meanwhil" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Custom%20E-mail%20Form%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Custom%20E-mail%20Form&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Custom%20E-mail%20Form&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcustom-e-mail-form%2F&amp;title=Custom%20E-mail%20Form" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/custom-e-mail-form/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Where to learn PHP</title>
		<link>http://www.davepcguy.com/archive/where-to-learn-php/</link>
		<comments>http://www.davepcguy.com/archive/where-to-learn-php/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 17:56:30 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=225</guid>
		<description><![CDATA[So you want to learn PHP, huh? I implore you to learn the HTML basics and some CSS first. CSS is not mandatory but it&#8217;ll come handy. HTML&#8217;s mandatory because of forms. Forms are essential for user data input and other actions in PHP. Use these websites as guidelines, you&#8217;ll have to learn PHP on]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=php&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>So you want to learn PHP, huh? I implore you to learn the HTML basics and some CSS first. CSS is not mandatory but it&#8217;ll come handy. HTML&#8217;s mandatory because of forms. Forms are essential for user data input and other actions in PHP.</p>
<p>Use these websites as guidelines, you&#8217;ll have to learn PHP on your own basically. Flip through them and whenever you can&#8217;t understand one part, get on another website and research it there. It&#8217;s how I&#8217;ve learned PHP. Get a book or two on PHP as well, they are structured very differently than online websites and some even feature a CD with example scripts. Most websites do not. Use this article wisely and most important of all, have fun.<br />
<br />
<span id="more-225"></span></p>
<p>So here we go:</p>
<hr />
<h1 style="padding: 15px"><strong>1.<a href="http://www.w3schools.com/default.asp"> W3Schools</a></strong></h1>
<p><strong><a href="http://www.davepcguy.com/wp-content/uploads/2009/09/w3schools.jpg"><img class="alignleft size-medium wp-image-226" title="w3schools" src="http://www.davepcguy.com/wp-content/uploads/2009/09/w3schools-300x202.jpg" alt="w3schools" width="300" height="202" /></a> </strong>W3Schools is an awesome resource. I&#8217;d say it&#8217;s a little more for the advanced users who know the terminology and the concepts beforehand. It features a full range of tutorials from how to write strings to making mail forms. They also show you how to implement AJAX with PHP and how to use MySQL databases with PHP in great detail. Most of the tutorials on this website are rather referential but they work out for the best. Once you get some of the basics down like how to set up functions, loops, your variables, and you understand the fundamentals of PHP, this website will be your greatest tool. It teaches you the advanced stuff as well as reviews the basics. Also, the website features a range full of references, ie for all the important sections of PHP, there is a reference sheet that briefly explains the function or the section and shows you all the ways it can be used. For example, if you want to use the date() function, there&#8217;s a <a href="http://www.w3schools.com/php/php_ref_date.asp">cheatsheet</a> where it shows you all the parameters you can use with this function.</p>
<p>This website useful not only for PHP but for other Web-Development code as well. There are tutorials on HTML, CSS, Javascript, XML, and others. So if you need to brush up on your forms, just click on the HTML tab and find the forms article in the left sidebar</p>
<hr />
<h1 style="padding: 15px"><strong>2. <a title="Zend tutorials PHP" href="http://devzone.zend.com/article/627" target="_blank">Zend Dev Zone</a></strong></h1>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/09/zend.jpg"><img class="size-medium wp-image-354 alignleft" title="zend" src="http://www.davepcguy.com/wp-content/uploads/2009/09/zend-300x168.jpg" alt="zend" width="300" height="168" /></a>Zend is a great piece of software, now what&#8217;s more amazing are the tutorials that the Zend Developer Zone features. The link above is to my favorite PHP tutorial. You can, of course, browse around the other tutorials offered. <a href="http://devzone.zend.com/article/627">This tutorial set</a> is the best I know of that&#8217;s for free and teaches you everything you need to know with a bit of humor and a lot of fun. The tutorial set goes through from the beginning of setting up a server at home and continues on with the basics such as defining a string, the basics of loops, and accessing databases. Everything you need to know is explained thoroughly and it&#8217;s very easy to understand, even the more heavy stuff like database modification, and object-oriented programming. At the end, the tutorial features a kind of &#8220;graduation&#8221; where you&#8217;ll create your own PHP app alongside the tutorial. It tests your understanding of the subject.</p>
<hr />
<h1 style="padding: 15px"><strong>3. <a title="tutsplus net tutorials" href="http://net.tutsplus.com/category/tutorials/" target="_blank">TutsPlus</a></strong></h1>
<div id="attachment_531" class="wp-caption alignleft" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/tutsplus.png"><img class="size-medium wp-image-531 " title="tutsplus" src="http://www.davepcguy.com/wp-content/uploads/2009/10/tutsplus-300x178.png" alt="tutsplus screenshot" width="300" height="178" /></a><p class="wp-caption-text">tutsplus screenshot</p></div>
<p>Nettuts+ is probably the best resource for an all-around person when it comes to design and web-development. These guys have tutorials on Photoshop, PHP, CSS, Illustrator, and many other for your convenience. They feature tutorials from the basics to the downright hardcore stuff. You can pay for the premium account and with that, you&#8217;ll receive special care such as scripts, and original files involved in their tutorials. I haven&#8217;t tried the video tutorials just yet but those are there as well for anyone to have fun with.</p>
<hr />
<h1 style="padding: 15px"><strong>4. <a title="good tutorials" href="http://net.tutsplus.com/category/tutorials/" target="_blank">Good-Tutorials</a></strong></h1>
<div id="attachment_580" class="wp-caption alignleft" style="width: 310px"><strong><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/goodtutorials.png"><img class="size-medium wp-image-580" title="goodtutorials" src="http://www.davepcguy.com/wp-content/uploads/2009/10/goodtutorials-300x187.png" alt="Good tutorials " width="300" height="187" /></a></strong><p class="wp-caption-text">Good tutorials </p></div>
<p>Good-tutorials.com is probably my favorite tutorial website. I did not learn PHP from there however. It&#8217;s a great website to find other websites, so to speak. If you look under the PHP section, you&#8217;ll find lots of great tutorials, tips&amp;tricks, that you&#8217;d never think would be available online for free. Through this site, I found all the others. They all feature their tutorials on good-tutorials. You can add your own tuts if you wish, it&#8217;s what I do. I recommend you use this site for PHP only after you learn the basics. If you want to learn anything other than PHP, such as how to use photoshop or illustrator, be sure to check this place out.</p>
<hr />
<p>Anyways, that&#8217;s it. Look through these sites and learn all you can. I hope this article helps you out on your road to learning PHP!</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;title=Where%20to%20learn%20PHP&amp;bodytext=So%20you%20want%20to%20learn%20PHP%2C%20huh%3F%20I%20implore%20you%20to%20learn%20the%20HTML%20basics%20and%20some%20CSS%20first.%20CSS%20is%20not%20mandatory%20but%20it%27ll%20come%20handy.%20HTML%27s%20mandatory%20because%20of%20forms.%20Forms%20are%20essential%20for%20user%20data%20input%20and%20other%20actions%20in%20PHP.%0D%0A%0D%0AUse%20these%20web" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;title=Where%20to%20learn%20PHP&amp;notes=So%20you%20want%20to%20learn%20PHP%2C%20huh%3F%20I%20implore%20you%20to%20learn%20the%20HTML%20basics%20and%20some%20CSS%20first.%20CSS%20is%20not%20mandatory%20but%20it%27ll%20come%20handy.%20HTML%27s%20mandatory%20because%20of%20forms.%20Forms%20are%20essential%20for%20user%20data%20input%20and%20other%20actions%20in%20PHP.%0D%0A%0D%0AUse%20these%20web" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;t=Where%20to%20learn%20PHP" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;title=Where%20to%20learn%20PHP&amp;annotation=So%20you%20want%20to%20learn%20PHP%2C%20huh%3F%20I%20implore%20you%20to%20learn%20the%20HTML%20basics%20and%20some%20CSS%20first.%20CSS%20is%20not%20mandatory%20but%20it%27ll%20come%20handy.%20HTML%27s%20mandatory%20because%20of%20forms.%20Forms%20are%20essential%20for%20user%20data%20input%20and%20other%20actions%20in%20PHP.%0D%0A%0D%0AUse%20these%20web" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;title=Where%20to%20learn%20PHP&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=So%20you%20want%20to%20learn%20PHP%2C%20huh%3F%20I%20implore%20you%20to%20learn%20the%20HTML%20basics%20and%20some%20CSS%20first.%20CSS%20is%20not%20mandatory%20but%20it%27ll%20come%20handy.%20HTML%27s%20mandatory%20because%20of%20forms.%20Forms%20are%20essential%20for%20user%20data%20input%20and%20other%20actions%20in%20PHP.%0D%0A%0D%0AUse%20these%20web" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;title=Where%20to%20learn%20PHP" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;t=Where%20to%20learn%20PHP&amp;s=So%20you%20want%20to%20learn%20PHP%2C%20huh%3F%20I%20implore%20you%20to%20learn%20the%20HTML%20basics%20and%20some%20CSS%20first.%20CSS%20is%20not%20mandatory%20but%20it%27ll%20come%20handy.%20HTML%27s%20mandatory%20because%20of%20forms.%20Forms%20are%20essential%20for%20user%20data%20input%20and%20other%20actions%20in%20PHP.%0D%0A%0D%0AUse%20these%20web" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Where%20to%20learn%20PHP%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Where%20to%20learn%20PHP&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Where%20to%20learn%20PHP&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fwhere-to-learn-php%2F&amp;title=Where%20to%20learn%20PHP" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/where-to-learn-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

