<?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; server</title>
	<atom:link href="http://www.davepcguy.com/archive/tag/server/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>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>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>Ubuntu 9.10 Karmic Koala is here!</title>
		<link>http://www.davepcguy.com/archive/ubuntu-9-10-karmic-koala-is-here/</link>
		<comments>http://www.davepcguy.com/archive/ubuntu-9-10-karmic-koala-is-here/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 17:56:24 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=764</guid>
		<description><![CDATA[source Phew, I was waiting for this. Ubuntu 9.10 has officially launched today. Go take the feature tour and see what it&#8217;s basically about if you know nothing about Ubuntu or Linux. So, here we are, 9.10 is here. It came out with three different versions: The Desktop Version: The version of Ubuntu meant 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%2Fubuntu-9-10-karmic-koala-is-here%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=computer,Linux,OS,server,software,ubuntu&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: center;">
<div class="wp-caption aligncenter" style="width: 448px"><img title="Karmic Koala" src="http://apcmag.com/images/Karmic-Koala.jpg" alt="Karmic Koala" width="438" height="329" /><p class="wp-caption-text">Karmic Koala</p></div>
<p><a title="karmic koala picture source" href="http://apcmag.com/images/Karmic-Koala.jpg">source</a></p>
<p style="text-align: center;">
<p><span id="more-764"></span></p>
<p>Phew, I was waiting for this. Ubuntu 9.10 has officially launched today. Go take the<a title="Ubuntu 9.10 feature tour." href="http://www.ubuntu.com/products/whatisubuntu/910features"> feature tour</a> and see what it&#8217;s basically about if you know nothing about <a title="What is ubuntu?" href="http://www.ubuntu.com/products/whatisubuntu">Ubuntu</a> or<a title="Linux wikipedia entry" href="http://en.wikipedia.org/wiki/Linux"> Linux</a>. So, here we are, 9.10 is here. It came out with three different versions:</p>
<ol>
<li>The Desktop Version: The version of Ubuntu meant to run on basically any computer built in the past almost ten years (I&#8217;m not joking).</li>
<li>The Server Edition: This one is meant to run on servers. It has all the required features (MySQL, PHP, Apache) as well as other derivatives</li>
<li>The Netbook Version: I can&#8217;t believe it came out this early, but the fully supported Netbook edition is already out!</li>
</ol>
<p>Also, don&#8217;t forget to visit <a title="kubuntu" href="http://www.kubuntu.org/">Kubuntu</a>, the 9.10 version is already out too! The new KDE release is packed with it. The <a title="edubuntu" href="http://www.edubuntu.org/">Edubuntu</a> is as well (this is the distro meant for education).</p>
<p><strong>Highlights:</strong></p>
<ul>
<li>the system is faster and more reliable.</li>
<li>the booting system looks neater (oh yeah, it looks way nicer)</li>
<li>the audio system has been completely reconstructed for wider support and better performance</li>
<li><a title="hundredpapercuts" href="https://launchpad.net/hundredpapercuts">One Hundred Paper Cuts</a> is up and running, dealing with all your every day annoyances with the system, and helping to solve those annoyances</li>
<li><a title="Ubuntu One" href="https://one.ubuntu.com/">Ubuntu One</a> project is also up and running, and with it, you get 2gb of online storage space that you can use with your Ubuntu installation</li>
<li>Programming is much easier with the use of &#8220;Quickly&#8221;  (should I try this one out? <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</li>
<li>For the netbook users, there&#8217;s a new, better interface system</li>
<li>Empathy is the new messenger. Yes, I have to stress this one. I&#8217;m a long time proponent of <a title="pidgin" href="http://www.pidgin.im">pidgin</a> and so I&#8217;ll have to truly see what Empathy has to offer</li>
<li>For the SERVER EDITION, Cloud computing has simplified lots with the <a title="UEC" href="http://www.ubuntu.com/products/whatisubuntu/serveredition/cloud/UEC">Ubuntu Enterprise Cloud (UEC)</a></li>
<li>All of the applications, of course, have been updated including <a title="Open Office" href="http://www.openoffice.org">OpeOffice</a>, Mozilla Firefox, and others</li>
</ul>
<p><strong>Other News:</strong></p>
<ul>
<li>The Kubuntu Netbook release will come out pretty soon, very exciting!</li>
<li>The <a title="ubuntu 9.10 technical overview" href="http://www.ubuntu.com/getubuntu/releasenotes/910overview">Technical Overview</a> of Ubuntu 9.10 is complete</li>
</ul>




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fubuntu-9-10-karmic-koala-is-here%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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;title=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;bodytext=%0D%0A%0D%0A%0D%0A%0D%0Asource%0D%0A%0D%0A%0D%0A%0D%0APhew%2C%20I%20was%20waiting%20for%20this.%20Ubuntu%209.10%20has%20officially%20launched%20today.%20Go%20take%20the%20feature%20tour%20and%20see%20what%20it%27s%20basically%20about%20if%20you%20know%20nothing%20about%20Ubuntu%20or%20Linux.%20So%2C%20here%20we%20are%2C%209.10%20is%20here.%20It%20came%20out%20with%20three" 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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;title=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;notes=%0D%0A%0D%0A%0D%0A%0D%0Asource%0D%0A%0D%0A%0D%0A%0D%0APhew%2C%20I%20was%20waiting%20for%20this.%20Ubuntu%209.10%20has%20officially%20launched%20today.%20Go%20take%20the%20feature%20tour%20and%20see%20what%20it%27s%20basically%20about%20if%20you%20know%20nothing%20about%20Ubuntu%20or%20Linux.%20So%2C%20here%20we%20are%2C%209.10%20is%20here.%20It%20came%20out%20with%20three" 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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;t=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21" 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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;title=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;annotation=%0D%0A%0D%0A%0D%0A%0D%0Asource%0D%0A%0D%0A%0D%0A%0D%0APhew%2C%20I%20was%20waiting%20for%20this.%20Ubuntu%209.10%20has%20officially%20launched%20today.%20Go%20take%20the%20feature%20tour%20and%20see%20what%20it%27s%20basically%20about%20if%20you%20know%20nothing%20about%20Ubuntu%20or%20Linux.%20So%2C%20here%20we%20are%2C%209.10%20is%20here.%20It%20came%20out%20with%20three" 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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;title=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=%0D%0A%0D%0A%0D%0A%0D%0Asource%0D%0A%0D%0A%0D%0A%0D%0APhew%2C%20I%20was%20waiting%20for%20this.%20Ubuntu%209.10%20has%20officially%20launched%20today.%20Go%20take%20the%20feature%20tour%20and%20see%20what%20it%27s%20basically%20about%20if%20you%20know%20nothing%20about%20Ubuntu%20or%20Linux.%20So%2C%20here%20we%20are%2C%209.10%20is%20here.%20It%20came%20out%20with%20three" 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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;title=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21" 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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;t=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;s=%0D%0A%0D%0A%0D%0A%0D%0Asource%0D%0A%0D%0A%0D%0A%0D%0APhew%2C%20I%20was%20waiting%20for%20this.%20Ubuntu%209.10%20has%20officially%20launched%20today.%20Go%20take%20the%20feature%20tour%20and%20see%20what%20it%27s%20basically%20about%20if%20you%20know%20nothing%20about%20Ubuntu%20or%20Linux.%20So%2C%20here%20we%20are%2C%209.10%20is%20here.%20It%20came%20out%20with%20three" 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=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fubuntu-9-10-karmic-koala-is-here%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=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fubuntu-9-10-karmic-koala-is-here%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=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fubuntu-9-10-karmic-koala-is-here%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%2Fubuntu-9-10-karmic-koala-is-here%2F&amp;title=Ubuntu%209.10%20Karmic%20Koala%20is%20here%21" 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/ubuntu-9-10-karmic-koala-is-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up (Part 1)</title>
		<link>http://www.davepcguy.com/archive/setting-up-part-1/</link>
		<comments>http://www.davepcguy.com/archive/setting-up-part-1/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 22:12:24 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[xampp]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=197</guid>
		<description><![CDATA[A short tutorial on setting up your own server under Windows using XAMPP. It also features a short WordPress installation and set-up guide. ]]></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%2Fsetting-up-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=server,wordpress,xampp&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Here&#8217;s the first part of my &#8220;Setting Up&#8221; tutorials. It will teach you how to set up to learn PHP, and for web development. It is my own personally journey as well because I&#8217;m getting ready to make new <a href="http://wordpress.org/extend/themes/">WordPress themes</a>. I&#8217;m using Windows XP, soon will be upgrading to Windows 7 (when it comes out) so most of my tutorials will be Windows-oriented.</p>
<p><strong>Installing the Server Software<br />
</strong></p>
<p>The best way to learn PHP and scripting is at home and without buying a domain nor paying for hosting. So let&#8217;s set up your computer as a server using <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a>. XAMPP stands for X (as in a variable instead of an OS name) Apache, MySQL, PHP, and PERL. You can use any other alternative depending on your operating system. There&#8217;s also <a href="http://www.wampserver.com/en/">WAMP</a> for Windows (I use this one) and <a href="http://www.mamp.info/en/index.html">MAMP</a> for Mac. All are basically the same with small differences. I&#8217;ll show you how to use XAMPP because it&#8217;s the most cross-platform package. I&#8217;ll do an article on how to set up your Linux with XAMPP later.</p>
<p><span id="more-197"></span></p>
<p>So what are these packages? They install the <a href="http://www.apache.org/">Apache</a> Server, <a href="http://www.mysql.com/">MySQL</a> database system, and <a href="http://www.php.net/">PHP</a> all in one. The packages are all set-up to interact and will save you a ton of time. You won&#8217;t have to install each program separately and try to intertwine them. It will all be done for you. Go to the <a href="http://www.apachefriends.org/en/xampp.html">XAMPP website</a>, select Windows and download the newest package available. Don&#8217;t get distracted by the add-ons.</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/09/picture1.jpg"><img class="size-thumbnail wp-image-199 alignleft" title="picture1" src="http://www.davepcguy.com/wp-content/uploads/2009/09/picture1-150x107.jpg" alt="picture1" width="150" height="107" /></a> Depending on the package that you downloaded, you&#8217;ll either have an executable file or an archive (zip). I downloaded the .exe for my windows because it was forty megs lighter and easier to set-up. Let&#8217;s move on. If you downloaded the .exe file, open it and install it in a folder. When choosing a destination folder, I recommend using your main drive (usually C:\) and a subfolder. I&#8217;m installing my XAMPP package into C:\server\, click install, follow the directions and you&#8217;re done. If you used the .zip download, extract all of the contents into a folder (C:\server\ for me) and follow the read me which tells you to use a couple .bat files to set-up everything. Once you&#8217;re done, start up the XAMPP Control Panel (it will be under start&gt;programs&gt;Xampp for Windows&gt; Xampp Control Panel). If you&#8217;re having problems with the Control Panel, start the MySQL and Apache services by double-clicking on apache_start.bat and mysql_start.bat in the main folder. </p>
<p>Here&#8217;s what the control panel looks like, it will list a different Windows version etc. but that&#8217;s alright:</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/09/picture2.jpg"><img class="size-medium wp-image-204 alignleft" title="picture2" src="http://www.davepcguy.com/wp-content/uploads/2009/09/picture2-300x252.jpg" alt="picture2" width="300" height="252" /></a>You can start up all the services shown by just clicking on start. I had some problem with it so I used the .bat files instead. Now point your web browser to http://127.0.0.1/ and you&#8217;ll see a XAMPP splash page, pick the language and let&#8217;s get going. I&#8217;ll cover all the features of XAMPP later tutorials, so for now, be happy that it works <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Keep your browser there and read on. Put all your PHP files and other files in &#8230;/xampp/htdocs/yourfoldername/ I set mine up /xampp/htdocs/learningPHP and I put an index.php file in there that will link me to all my scripts and tutorials that I absolved (ie. &lt;a href=&#8221;tutorial1.php&#8221;&gt;tutorial one&lt;/a&gt;). This will keep your folders organized and it&#8217;ll be easier to find these files. Type in http://127.0.0.1/learningPHP and you&#8217;ll get to your index.php file there. Unlike WAMP, XAMPP doesn&#8217;t seem to have a listing directory on its server but don&#8217;t worry too much about that. We&#8217;re set-up and ready to go. If you didn&#8217;t get any of this, don&#8217;t worry  about it. Just remember to make a new folder in /htdocs/ where you can store your php scripts and other stuff. Also, remember that unless you set up your apache and mysql as services (the process is in the readme file and included in the .exe installation), you&#8217;ll have to start them every time you start up your computer.<br />
To get rid of XAMPP, simply delete the folder or use the provided &#8220;uninstall_xampp.bat&#8221; file</p>
<p><strong>Setting up the Database</strong></p>
<p>While in your browser is at http://127.0.0.1/xampp/ Click on PHPmyadmin and follow these directions.</p>
<ol>
<li>click on the &#8220;privileges&#8221; tab</li>
<li>add a new user</li>
<li>type in your user name, I&#8217;ll use the user name &#8220;Alexander&#8221;</li>
<li>under the host tab, click &#8220;local&#8221; and it&#8217;ll fill out localhost in the field next to it</li>
<li>type in a password, I&#8217;ll use &#8220;davepcguy&#8221;</li>
<li>Database for user: none</li>
<li>check all privileges (it&#8217;s the easiest and as long as you don&#8217;t put your server online, it&#8217;ll be safe)</li>
<li>click &#8220;Go&#8221;</li>
<li>go back to &#8220;Databases&#8221;</li>
<li>under Create New Database, create one, I created &#8220;WP&#8221; for my WordPress</li>
</ol>
<p>Now I have a database named &#8220;WP&#8221; under the username &#8220;Alexander&#8221; with the password &#8220;davepcguy&#8221;</p>
<p>Your database list should look like this:</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/09/databases.jpg"><img class="aligncenter size-full wp-image-205" title="databases" src="http://www.davepcguy.com/wp-content/uploads/2009/09/databases.jpg" alt="databases" width="232" height="222" /></a>The first five databases are preset, and my &#8220;wp&#8221; database is the one I made.</p>
<p><strong>Setting up WordPress:</strong></p>
<p>First, go download <a href="http://wordpress.org/">WordPress</a>.</p>
<p>then:</p>
<ol>
<li>extract the zip file into htdocs</li>
<li>change &#8220;wp-config-sample.php&#8221; to &#8220;wp-config.php&#8221;</li>
<li>open the file with your PHP editor. You can also use your text editor if you don&#8217;t have a PHP editor yet. I&#8217;ll post a short tutorial on setting up your PHP editor later.</li>
<li>find this section:
<pre name="code" class="php:nocontrols:nogutter"> // ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'putyourdbnamehere');

/** MySQL database username */
define('DB_USER', 'usernamehere');

/** MySQL database password */
define('DB_PASSWORD', 'yourpasswordhere');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');</pre>
</li>
<li>Change &#8220;putyourdbnamehere&#8221; to the database name you created, in my case it would be &#8220;wp&#8221;</li>
<li>Change &#8220;usernamehere&#8221; to the username we set up earlier, in my case that would be &#8220;Alexander&#8221;</li>
<li>Change &#8220;yourpasswordhere&#8221; to your password we set earlier, in my case it would be &#8220;davepcguy&#8221;</li>
<li>save the file and your result should look like this:
<pre name="code" class="php:nocontrols:nogutter">// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wp');

/** MySQL database username */
define('DB_USER', 'Alexander');

/** MySQL database password */
define('DB_PASSWORD', 'davepcguy');

/** MySQL hostname */
define('DB_HOST', 'localhost');</pre>
</li>
<li>go to: http://127.0.0.1/wordpress</li>
</ol>
<p>Now let&#8217;s install WordPress. Type in the blog title and your e-mail. Press &#8220;install&#8221;. It will give you a randomly generated password. Copy that password and click &#8220;Log in&#8221;. Type &#8220;Admin&#8221; as user name and paste the password. Viola, you got your own home WordPress blog set up!</p>
<p>A couple of tips:</p>
<ul>
<li>go change your password immediately, there should be a link on top of the page to do that</li>
<li>your wordpress password and your MySQL password are NOT the same</li>
<li>you can always change your e-mail and password under Users&gt;your profile</li>
<li>before you start posting blog-posts, change your nickname from &#8220;admin&#8221; to something else</li>
<li>to log in next time, go back to &#8220;http://127.0.0.1/wordpress&#8221; and find the login button at the bottom of the right sidebar</li>
</ul>
<p>That&#8217;s all you need to start messing around with PHP and WordPress for now. Have fun figuring out WordPress, I&#8217;ll have a tutorial ready later to explain how to use its functions fully but you probably won&#8217;t need that. Also, note that this set-up is for home use only. I&#8217;d suggest a better username and password if you were to host your blog online. Setting up a WordPress blog online is a bit different, there is no &#8220;phpmyadmin&#8221; and you&#8217;ll have to create a database differently, and probably using software your host provides. Enjoy! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 1666px; width: 1px; height: 1px;">http://127.0.0.1/wordpressgo</div>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsetting-up-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%2Fsetting-up-part-1%2F&amp;title=Setting%20up%20%28Part%201%29&amp;bodytext=A%20short%20tutorial%20on%20setting%20up%20your%20own%20server%20under%20Windows%20using%20XAMPP.%20It%20also%20features%20a%20short%20WordPress%20installation%20and%20set-up%20guide.%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%2Fsetting-up-part-1%2F&amp;title=Setting%20up%20%28Part%201%29&amp;notes=A%20short%20tutorial%20on%20setting%20up%20your%20own%20server%20under%20Windows%20using%20XAMPP.%20It%20also%20features%20a%20short%20WordPress%20installation%20and%20set-up%20guide.%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%2Fsetting-up-part-1%2F&amp;t=Setting%20up%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%2Fsetting-up-part-1%2F&amp;title=Setting%20up%20%28Part%201%29&amp;annotation=A%20short%20tutorial%20on%20setting%20up%20your%20own%20server%20under%20Windows%20using%20XAMPP.%20It%20also%20features%20a%20short%20WordPress%20installation%20and%20set-up%20guide.%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%2Fsetting-up-part-1%2F&amp;title=Setting%20up%20%28Part%201%29&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=A%20short%20tutorial%20on%20setting%20up%20your%20own%20server%20under%20Windows%20using%20XAMPP.%20It%20also%20features%20a%20short%20WordPress%20installation%20and%20set-up%20guide.%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%2Fsetting-up-part-1%2F&amp;title=Setting%20up%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%2Fsetting-up-part-1%2F&amp;t=Setting%20up%20%28Part%201%29&amp;s=A%20short%20tutorial%20on%20setting%20up%20your%20own%20server%20under%20Windows%20using%20XAMPP.%20It%20also%20features%20a%20short%20WordPress%20installation%20and%20set-up%20guide.%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=Setting%20up%20%28Part%201%29%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsetting-up-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=Setting%20up%20%28Part%201%29&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsetting-up-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=Setting%20up%20%28Part%201%29&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fsetting-up-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%2Fsetting-up-part-1%2F&amp;title=Setting%20up%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/setting-up-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

