<?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"
	>

<channel>
	<title>CodeGrrl.com</title>
	<atom:link href="http://codegrrl.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codegrrl.com</link>
	<description>Taking the grr out of coding!</description>
	<pubDate>Fri, 02 May 2008 12:46:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>CodeGrrl Running on WordPress</title>
		<link>http://codegrrl.com/updates/codegrrl-running-on-wordpress</link>
		<comments>http://codegrrl.com/updates/codegrrl-running-on-wordpress#comments</comments>
		<pubDate>Sun, 27 Apr 2008 20:34:15 +0000</pubDate>
		<dc:creator>Vixx</dc:creator>
		
		<category><![CDATA[CodeGrrl]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://codegrrl.com/?p=195</guid>
		<description><![CDATA[If you&#8217;re seeing this, it means that our transition from Expression Engine to WordPress has all gone according to plan! We&#8217;ve made the switch because we&#8217;re firm believers in celebrating open source, and we&#8217;re much more comfortable navigating the WordPress dashboard than EE. 
There&#8217;s still no doubt a few teething issues to iron out (for [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re seeing this, it means that our transition from Expression Engine to WordPress has all gone according to plan! We&#8217;ve made the switch because we&#8217;re firm believers in celebrating open source, and we&#8217;re much more comfortable navigating the WordPress dashboard than EE. </p>
<p>There&#8217;s still no doubt a few teething issues to iron out (for instance, right now we still need to sort the pages out!) but the database and accompanying users, scripts and resources have all ported over successfully.</p>
<p>A massive, <em>massive</em> thank you to <a href="http://codegrrl.com/forums/index.php?showuser=2051">Amelie</a> who spent hours getting us prepared for the migration. <img src='http://codegrrl.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/updates/codegrrl-running-on-wordpress/feed</wfw:commentRss>
		</item>
		<item>
		<title>WordPress &#187; Wordpress Automatic upgrade</title>
		<link>http://codegrrl.com/resources/wordpress-automatic-upgrade</link>
		<comments>http://codegrrl.com/resources/wordpress-automatic-upgrade#comments</comments>
		<pubDate>Thu, 03 Apr 2008 18:45:21 +0000</pubDate>
		<dc:creator>Vixx</dc:creator>
		
		<category><![CDATA[Resources]]></category>

		<category><![CDATA[upgrade]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[wordpress upgrade]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=191</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/resources/wordpress-automatic-upgrade/feed</wfw:commentRss>
		</item>
		<item>
		<title>&#124;&#124; Dummy Text Generator &#124; Lorem ipsum for webdesigners &#124;&#124;</title>
		<link>http://codegrrl.com/resources/dummy-text-generator-lorem-ipsum-for-webdesigners</link>
		<comments>http://codegrrl.com/resources/dummy-text-generator-lorem-ipsum-for-webdesigners#comments</comments>
		<pubDate>Mon, 25 Feb 2008 18:46:53 +0000</pubDate>
		<dc:creator>Vixx</dc:creator>
		
		<category><![CDATA[Resources]]></category>

		<category><![CDATA[text generator]]></category>

		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=194</guid>
		<description><![CDATA[A handy Lorem Ipsum Generator that helps to create dummy text for all layout needs.
]]></description>
			<content:encoded><![CDATA[<p>A handy Lorem Ipsum Generator that helps to create dummy text for all layout needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/resources/dummy-text-generator-lorem-ipsum-for-webdesigners/feed</wfw:commentRss>
		</item>
		<item>
		<title>New Staff Wanted!</title>
		<link>http://codegrrl.com/updates/new-staff-wanted</link>
		<comments>http://codegrrl.com/updates/new-staff-wanted#comments</comments>
		<pubDate>Tue, 18 Dec 2007 16:12:29 +0000</pubDate>
		<dc:creator>Vixx</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=5</guid>
		<description><![CDATA[I will be taking on some more staff here at CodeGrrl to help with the maintenance and development of this site. Please read on if you&#8217;re interested in becoming part of the staff!
I&#8217;m looking for people who can do any of the following: Write coding-related tutorials; Add code snippets; Help update the FAQ and Contribute [...]]]></description>
			<content:encoded><![CDATA[<p>I will be taking on some more staff here at CodeGrrl to help with the maintenance and development of this site. Please read on if you&#8217;re interested in becoming part of the staff!</p>
<p>I&#8217;m looking for people who can do any of the following: Write coding-related tutorials; Add code snippets; Help update the FAQ and Contribute regularly to the forum and help people out.</p>
<p>It helps if you have a decent grasp of the main scripting languages. However, for the Tutorial and Snippet sections, anything code-related is okay (think HTML, CSS, Javascript, Ruby on Rails, ASP, etc). I&#8217;m also looking for people who could write tutorials for PC maintenance, Photoshop, blog scripts (WP, EE etc.) SEO - so it&#8217;s not just about writing scripts!</p>
<p>If you&#8217;re interested in helping me out with this please send me an email at mail[at] furious-angel.com with the following information:</p>
<ul>
<li>Your name</li>
<li>Your email</li>
<li>Your site URL</li>
<li>Your username at the forum</li>
<li>And tell me what coding languages you know or have had experience with, and why you&#8217;d like to join the staff.</li>
</ul>
<p>I am looking for friendly, committed people prepared to help get CG back on track, people willing to write tutorials and contribute to the knowledge base here.</p>
<p>Thanks a million to anyone in advance for being willing to help me out. <img src='http://codegrrl.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Any questions, just ask!</p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/updates/new-staff-wanted/feed</wfw:commentRss>
		</item>
		<item>
		<title>PHPAskIt removed from CodeGrrl</title>
		<link>http://codegrrl.com/updates/phpaskit-removed-from-codegrrl</link>
		<comments>http://codegrrl.com/updates/phpaskit-removed-from-codegrrl#comments</comments>
		<pubDate>Sun, 18 Nov 2007 17:21:19 +0000</pubDate>
		<dc:creator>Amelie</dc:creator>
		
		<category><![CDATA[Scripts]]></category>

		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=169</guid>
		<description><![CDATA[PHPAskIt is no longer available at CodeGrrl. If you would like to download the script in future, please visit its new home.
]]></description>
			<content:encoded><![CDATA[<p>PHPAskIt is no longer available at CodeGrrl. If you would like to download the script in future, <a href="http://not-noticeably.net/scripts/phpaskit/">please visit its new home</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/updates/phpaskit-removed-from-codegrrl/feed</wfw:commentRss>
		</item>
		<item>
		<title>And another new server!</title>
		<link>http://codegrrl.com/updates/and-another-new-server</link>
		<comments>http://codegrrl.com/updates/and-another-new-server#comments</comments>
		<pubDate>Fri, 07 Sep 2007 17:35:40 +0000</pubDate>
		<dc:creator>Sasha</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=172</guid>
		<description><![CDATA[Sorry for the slight downtime today, but I&#8217;ve had to move CodeGrrl to a new server once again. We&#8217;ve outgrown DreamHost&#8217;s shared package, and I am currently unable to afford upgrading to one of their $400 a month dedicated servers. Thanks to Vixx and Maja, we have a lovely new home on one of Maja&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the slight downtime today, but I&#8217;ve had to move CodeGrrl to a new server once again. We&#8217;ve outgrown DreamHost&#8217;s shared package, and I am currently unable to afford upgrading to one of their $400 a month dedicated servers. Thanks to <a href="http://furious-angel.com/" title="Vixx">Vixx</a> and <a href="http://branwen.net/" title="Maja">Maja</a>, we have a lovely new home on one of Maja&#8217;s servers. I think this is everything back up and running, but it&#8217;s getting quite late here and I&#8217;m tired, so if you spot any errors I missed (and I&#8217;m sure there are some!!) <a href="http://codegrrl.com/forums/index.php?showtopic=16308" title="please let us know">please let us know</a>! <img src='http://codegrrl.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Thanks, and apologies once again for the downtime!</p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/updates/and-another-new-server/feed</wfw:commentRss>
		</item>
		<item>
		<title>Part 12: Paginating your entries</title>
		<link>http://codegrrl.com/tutorials/part-12-paginating-your-entries</link>
		<comments>http://codegrrl.com/tutorials/part-12-paginating-your-entries#comments</comments>
		<pubDate>Sat, 28 Apr 2007 21:59:06 +0000</pubDate>
		<dc:creator>Amelie</dc:creator>
		
		<category><![CDATA[Build A Blog]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=8</guid>
		<description><![CDATA[Many people have asked how to paginate their blog&#8217;s front page so as to show the previous/next 5 entries, for example. This tutorial was originally posted on the forums by Amanda.


Add this code to the blog page that displays your entries after you have your MySQL connection information:
$blog_postnumber = 5;
The number after the = is [...]]]></description>
			<content:encoded><![CDATA[<p>Many people have asked how to paginate their blog&#8217;s front page so as to show the previous/next 5 entries, for example. This tutorial was originally posted on the <a href="/forums/">forums</a> by Amanda.</p>
<p><span id="more-8"></span></p>
<ol>
<li>Add this code to the blog page that displays your entries after you have your MySQL connection information:
<pre>$blog_postnumber = 5;</pre>
<p>The number after the = is the number of posts you want displayed on your blog.</p>
</li>
<li>Next, add this underneath the above code:
<pre>if(!isset($_GET['page'])) {
	$page = 1;
}
else {
	$page = (int)$_GET['page'];
}
$from = (($page * $blog_postnumber) - $blog_postnumber);</pre>
</li>
<li>Assuming you have kept the code of your blog index page as it is in the past tutorials, you should have this line near the top of the page:
<pre>$sql = &quot;SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5&quot;;</pre>
<p>You should change that code to the following:</p>
<pre>$sql = &quot;SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT $from, $blog_postnumber&quot;;</pre>
</li>
<li>The next step is to link the pages. To do this, add the following code to the bottom of your index page. It will calculate how many pages are needed based on how many posts you have, and how many you want to display on each page. It will then link the pages for you.
<pre>$total_results = mysql_fetch_array(mysql_query(&quot;SELECT COUNT(*) as num FROM php_blog&quot;));
$total_pages = ceil($total_results['num'] / $blog_postnumber);
if ($page &gt; 1) {
    $prev = ($page - 1);
    echo &quot;&lt;a href=\&quot;index.php?page=$prev\&quot;&gt;&amp;lt;&amp;lt;  Newer&lt;/a&gt;&nbsp;&quot;;
}
for($i = 1; $i &lt;= $total_pages; $i++) {
    if ($page == $i) {
        echo &quot;$i&nbsp;&quot;;
        }
		else {
           echo &quot;&lt;a href=\&quot;index.php?page=$i\&quot;&gt;$i&lt;/a&gt;&nbsp;&quot;;
        }
}
if ($page &lt; $total_pages) {
   $next = ($page + 1);
   echo &quot;&lt;a href=\&quot;index.php?page=$next\&quot;&gt;Older &amp;gt;&amp;gt;&lt;/a&gt;&quot;;
}</pre>
<p>For this last part to work, it&#8217;s assuming the page with your blog entry list is named index.php. If it&#8217;s not, you can change the index.php part in the last code. (It&#8217;s listed 3 times.)</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/tutorials/part-12-paginating-your-entries/feed</wfw:commentRss>
		</item>
		<item>
		<title>Part 11: Categories</title>
		<link>http://codegrrl.com/tutorials/part-11-categories</link>
		<comments>http://codegrrl.com/tutorials/part-11-categories#comments</comments>
		<pubDate>Fri, 27 Apr 2007 22:12:34 +0000</pubDate>
		<dc:creator>Amelie</dc:creator>
		
		<category><![CDATA[Build A Blog]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=65</guid>
		<description><![CDATA[This tutorial will teach you how to add simple categories to your blog.



The first thing we need to do is to add a category table to our database. We could just list the categories in the entries table, but this can cause problems if you need to rename a category. Doing it this way means [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will teach you how to add simple categories to your blog.</p>
<p><span id="more-65"></span></p>
<ol>
<li>
<p>The first thing we need to do is to add a category table to our database. We could just list the categories in the entries table, but this can cause problems if you need to rename a category. Doing it this way means that the category will change everywhere if you edit it once.</p>
<p>First, we need to connect to MySQL.</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');</pre>
<p>(Remember to add your own details)</p>
<p>Next we select the database to use:</p>
<pre>mysql_select_db('db_name');</pre>
<p>Second, we tell MySQL to add our table to the database. We will need two columns, one which will be the category ID number, and the other which will be the category name. We will give our category field a limit of 255 characters, since anything longer than that is unlikely. Our ID numbers will be automatically incremented and unique, so we must tell MySQL to do this for us. We will also tell it that the ID will be an unsigned number (i.e., it won&#8217;t be negative) and that the number won&#8217;t go over 9999 (4 digits, in other words).</p>
<p>This is the code we will use:</p>
<pre>$result = mysql_query(&quot;CREATE TABLE php_blog_categories
(`category_id` smallint(4) UNSIGNED AUTO_INCREMENT NOT NULL,
`category_name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`category_id`))&quot;);</pre>
<p>Because each category ID number relates to the category name, we will assign it as our primary key. This helps MySQL to associate the different IDs to the category names, and this will help us to match entries to categories. It also makes sure that we never have a duplicate ID number.</p>
<p>We will run that command through MySQL. To check if it worked or not, we will add a snippet to the script, which will check whether the query was successful (true) or not. If it wasn&#8217;t, we&#8217;d like MySQL to tell us why:</p>
<pre>if ($result == true) echo 'Table created successfully.';
else 'Table could not be created. ' . mysql_error();</pre>
<p>Then we will close MySQL and PHP.</p>
<pre>mysql_close();
?&gt;</pre>
<p>The complete table script should look like this:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

$result = mysql_query(&quot;CREATE TABLE php_blog_categories
(`category_id` smallint(4) UNSIGNED AUTO_INCREMENT NOT NULL,
`category_name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`category_id`))&quot;);

if ($result == true) echo 'Table created successfully.';
else 'Table could not be created. ' . mysql_error();

mysql_close();
?&gt;</pre>
<p>Run this just like you did when creating the initial table in part 1. If you get a success message, you are ready to move onto step 2.</p>
</li>
<li>
<p>The next thing to do is to add a column to our entries table to show which category a post is in. We will be doing this using the category&#8217;s ID number, not the category name. Let&#8217;s say we have a category called &quot;work&quot;, which has an ID of 1. All entries that are categorised under &quot;work&quot; will have the number 1 in their category column, and MySQL will translate that ID, using the table we just created, to its proper name. It sounds complicated, but it really isn&#8217;t!</p>
<p>We will be altering the entries table just like we did for the password in part 4. We will run a quick snippet, just like the one above, to change the table. We need to tell the table that we would like a new column called category, and that it will have the same details as the category ID table (except that it does not need to be unique - one category can contain many entries). This is the code we will use:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

$result = mysql_query(&quot;ALTER TABLE php_blog ADD `category` smallint(4) UNSIGNED NOT NULL&quot;);

if ($result == true) echo 'Table altered successfully.';
else 'Table could not be altered. ' . mysql_error();

mysql_close();
?&gt;</pre>
<p>Run that just like above, and once again if you got a success message you are ready for the next step.</p>
</li>
<li>
<p>Now we must add a page that will manage categories for us. We want to be able to add, rename and delete categories, and this part will teach you how to do this.</p>
<p>Here is the code that we will use:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

if (isset($_POST['add_category'])) {

}
elseif (isset($_POST['edit_category'])) {

}
elseif (isset($_POST['delete_category'])) {

}
else {

}

mysql_close();
?&gt;</pre>
<p>Obviously this is not the complete code, it is the outline for what we want to do. First we are checking whether any of the form buttons were pressed, and which one it was. If no button was pressed, we will get the page to show us all our existing categories.</p>
<p>This is the first thing we will do, even though it comes last in the code structure, as it will help you to see how the categories are processed. It&#8217;s also the easiest part <img src='http://codegrrl.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>As I said, the categories will be shown, along with options of what to do with them, by default on the page.</p>
<p>Find this part in the code structure I posted above:</p>
<pre>else {

}</pre>
<p>Between the { and the }, we will get our categories from the database. This is how we will do it:</p>
<p>First, let&#8217;s get the details from the database.</p>
<pre>$result = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);</pre>
<p>Second, let&#8217;s close PHP so we can add some HTML code to format the categories before we show them. We also need to create the form that will tell PHP what we want doing with a category.</p>
<pre>?&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;&lt;p&gt;</pre>
<p>Then we will reopen PHP, and start showing our results in a loop (so that we don&#8217;t have to keep repeating the database selection every time). This is the same principle we used when showing the blog entries.</p>
<pre>&lt;?php
while($row = mysql_fetch_array($result)) {
?&gt;</pre>
<p>Here I have closed PHP again, as it will make it easier to see what we are doing. Now we are going to create a list of all the categories, like so:</p>
<pre>&lt;input type=&quot;radio&quot; name=&quot;category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt; &lt;?php echo $row['category_name']; ?&gt;&lt;br /&gt;</pre>
<p>When run by PHP, the HTML will be &#8216;filled in&#8217;, and will look something like this:</p>
<pre>&lt;input type=&quot;radio&quot; name=&quot;category&quot; value=&quot;1&quot; /&gt; Work</pre>
<p>That code will repeat for every category you have.</p>
<p>Now we go back into PHP and and close the while loop:</p>
<pre>&lt;?php
}
?&gt;</pre>
<p>Then we come out of it again, and add our HTML for the edit and delete buttons and the end of the form. Underneath, we will also add a new form to add a new category.</p>
<pre>&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;edit_category&quot; id=&quot;edit_category&quot; value=&quot;Edit selected category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;delete_category&quot; id=&quot;delete_category&quot; value=&quot;Delete selected category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
&lt;p&gt;Add new category: &lt;input type=&quot;text&quot; name=&quot;new_category&quot; id=&quot;new_category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;add_category&quot; id=&quot;add_category&quot; value=&quot;Add category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;</pre>
<p>We then need to reopen PHP to continue the script.</p>
<pre>&lt;?php</pre>
<p>The complete code for categories.php should look like this now:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

if (isset($_POST['add_category'])) {

}
elseif (isset($_POST['edit_category'])) {

}
elseif (isset($_POST['delete_category'])) {

}
else {

$result = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);
?&gt;
&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;&lt;p&gt;

&lt;?php
while($row = mysql_fetch_array($result)) {
?&gt;

&lt;input type=&quot;radio&quot; name=&quot;category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt; &lt;?php echo $row['category_name']; ?&gt;&lt;br /&gt;

&lt;?php
}
?&gt;

&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;edit_category&quot; id=&quot;edit_category&quot; value=&quot;Edit selected category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;delete_category&quot; id=&quot;delete_category&quot; value=&quot;Delete selected category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
&lt;p&gt;Add new category: &lt;input type=&quot;text&quot; name=&quot;new_category&quot; id=&quot;new_category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;add_category&quot; id=&quot;add_category&quot; value=&quot;Add category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;?php
}

mysql_close();
?&gt;</pre>
<p>At the moment, you will most likely not have any categories, as you have just created the tables, so running the categories.php as it is will probably result in a blank page with just the buttons. Don&#8217;t worry! That is normal.</p>
</li>
<li>
<p>Next we will process category addition.</p>
<p>Find the following part in your code:</p>
<pre>if (isset($_POST['add_category'])) {

}</pre>
<p>Between those {}s, we will add our processing code.</p>
<p>First we will strip HTML and convert special characters as both a security precaution and to prevent problems with category names.</p>
<pre>$newcat = htmlspecialchars(strip_tags($_POST['new_category']));</pre>
<p>Next, we need to check if a category was submitted. If the text box was left blank, we will display an error and stop the script from going any further. You might ask why we are doing this after stripping invalid characters from the category - we do it afterwards in case the category was made up only of invalid characters. If the entire category name is stripped out, it will be as if the person didn&#8217;t enter anything at all.</p>
<pre>if (empty($newcat)) {
die(&quot;No category submitted! Please go back and enter one.&quot;);
}</pre>
<p>If the category is not empty, the script will be allowed to continue (it will stop and display an error if the category is empty), so we don&#8217;t need an else statement for the next part, which is to add the category to the database.</p>
<p>Before we add the code to the database, we need to escape quotes. On most servers this is done automatically, but if it isn&#8217;t, you&#8217;ll have problems adding new categories containing quotes.</p>
<p>First we need to check whether the server will escape the quotes for us. Because we only need to do something if the server doesn&#8217;t escape the quotes, that is what we will check for, hence the ! in the if statement.</p>
<pre>if (!get_magic_quotes_gpc()) {
$newcat = mysql_real_escape_string($newcat);
}</pre>
<p>mysql_real_escape_string() will escape the quotes for us. It is similar to addslashes() which is used in previous parts of the Build A Blog tutorials, but mysql_real_escape_string() is especially suited for MySQL databases so is better to use than addslashes().</p>
<p>Here is the code we will use to submit the new category to the database:</p>
<pre>$insert = mysql_query(&quot;INSERT INTO php_blog_categories (`category_name`) VALUES ('$newcat')&quot;);</pre>
<p>We then check to see if the category was successfully submitted:</p>
<pre>if ($insert == true) echo 'Category successfully added.';
else echo 'The category could not be added to the database. ' . mysql_error();</pre>
<p>Now our complete code should look like this:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

if (isset($_POST['add_category'])) {

$newcat = htmlspecialchars(strip_tags($_POST['new_category']));

if (empty($newcat)) {
die( &quot;No category submitted! Please go back and enter one.&quot;);
}

if (!get_magic_quotes_gpc()) {
$newcat = mysql_real_escape_string($newcat);
}

$insert = mysql_query(&quot;INSERT INTO php_blog_categories (`category_name`) VALUES (&#8217;$newcat&#8217;)&quot;);

if ($insert == true) echo &#8216;Category successfully added.&#8217;;
else echo &#8216;The category could not be added to the database. &#8216; . mysql_error();

}
elseif (isset($_POST['edit_category'])) {

}
elseif (isset($_POST['delete_category'])) {

}
else {

$result = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);
?&gt;
&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;&lt;p&gt;

&lt;?php
while($row = mysql_fetch_array($result)) {
?&gt;

&lt;input type=&quot;radio&quot; name=&quot;category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt; &lt;?php echo $row['category_name']; ?&gt;&lt;br /&gt;

&lt;?php
}
?&gt;

&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;edit_category&quot; id=&quot;edit_category&quot; value=&quot;Edit selected category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;delete_category&quot; id=&quot;delete_category&quot; value=&quot;Delete selected category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
&lt;p&gt;Add new category: &lt;input type=&quot;text&quot; name=&quot;new_category&quot; id=&quot;new_category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;add_category&quot; id=&quot;add_category&quot; value=&quot;Add category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;?php
}

mysql_close();
?&gt;</pre>
</li>
<li>The next part we will do is category deletion, as editing is a little bit harder. We will do that part last.
<p>The code to delete entries is very similar to the code to add entries - we will check to see if a value was submitted, and if that value was a number (the category ID). Then we will take that value, and delete the category to which that ID number corresponds.</p>
<p>So, find this part in your code:</p>
<pre>elseif (isset($_POST['delete_category'])) {

}</pre>
<p>As usual, we will add our new code between the braces ( { and } ).</p>
<p>Let&#8217;s make sure the category that was submitted is valid (i.e. a number):</p>
<pre>$category = (int)$_POST['category'];</pre>
<p>Next, let&#8217;s see if a category was actually chosen for deletion (again, we do this after checking that the category is a number, as if it isn&#8217;t it will have been stripped out by the above code and will be equivalent to not having chosen a category to delete).</p>
<pre>if (empty($category)) {
die(&quot;No category chosen! Please go back and choose a category to delete.&quot;);
}</pre>
<p>If the above did not fail, we are sure we have an ID number. Let&#8217;s delete its corresponding category from the database:</p>
<pre>$delete = mysql_query(&quot;DELETE FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);</pre>
<p>I&#8217;ve added a LIMIT 1 to the end, because although we are meant to have unique category ID numbers, if, for whatever reason you end up with two categories with the same ID number, we only want to delete one of the entries. LIMIT 1 will make sure that this happens.</p>
<p>Now we will test to see if the category was deleted successfully:</p>
<pre>if ($delete == true) echo 'Category successfully deleted.';
else echo 'The category could not be deleted. ' . mysql_error();</pre>
<p>The complete code should now look like this:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

if (isset($_POST['add_category'])) {

$newcat = htmlspecialchars(strip_tags($_POST['new_category']));

if (empty($newcat)) {
die( &quot;No category submitted! Please go back and enter one.&quot;);
}

if (!get_magic_quotes_gpc()) {
$newcat = mysql_real_escape_string($newcat);
}

$insert = mysql_query(&quot;INSERT INTO php_blog_categories (`category_name`) VALUES (&#8217;$newcat&#8217;)&quot;);

if ($insert == true) echo &#8216;Category successfully added.&#8217;;
else echo &#8216;The category could not be added to the database. &#8216; . mysql_error();

}
elseif (isset($_POST['edit_category'])) {

}
elseif (isset($_POST['delete_category'])) {

$category = (int)$_POST['category'];

if (empty($category)) {
die(&quot;No category chosen! Please go back and choose a category to delete.&quot;);
}

$delete = mysql_query(&quot;DELETE FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);

if ($delete == true) echo &#8216;Category successfully deleted.&#8217;;
else echo &#8216;The category could not be deleted. &#8216; . mysql_error();

}
else {

$result = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);
?&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;&lt;p&gt;

&lt;?php
while($row = mysql_fetch_array($result)) {
?&gt;

&lt;input type=&quot;radio&quot; name=&quot;category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt; &lt;?php echo $row['category_name']; ?&gt;&lt;br /&gt;

&lt;?php
}
?&gt;

&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;edit_category&quot; id=&quot;edit_category&quot; value=&quot;Edit selected category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;delete_category&quot; id=&quot;delete_category&quot; value=&quot;Delete selected category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
&lt;p&gt;Add new category: &lt;input type=&quot;text&quot; name=&quot;new_category&quot; id=&quot;new_category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;add_category&quot; id=&quot;add_category&quot; value=&quot;Add category&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;

&lt;?php
}

mysql_close();
?&gt;</pre>
</li>
<li>The next stage is to edit our categories. This is slightly more complicated than the other steps, as we first need to select the category we want to edit, show a form to edit it, then submit the changes to the database.
<p>First, find the only remaining &quot;blank&quot; part of your code (i.e. a part which doesn&#8217;t do anything), which is this part:</p>
<pre>elseif (isset($_POST['edit_category'])) {

}</pre>
<p>Between the {}s we will start our new code.</p>
<p>Let&#8217;s make sure the category is a number and that it is not empty (this is the exact same process we used for the deleting part):</p>
<pre>$category = (int)$_POST['category'];

if (empty($category)) {
die (&quot;No category chosen! Please go back and choose a category to edit.&quot;);
}
</pre>
<p>Next we will get the current category name from the database:</p>
<pre>$result = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);
$row = mysql_fetch_array($result);</pre>
<p>Let&#8217;s check that the category actually exists. If it doesn&#8217;t, we will get errors everywhere or a blank page (depends on server settings), so let&#8217;s tell the user and exit the script before this has a chance to happen.</p>
<pre>if (!$row) {
die(&quot;There doesn't seem to be a category with the ID number submitted. Please go back and try again.&quot;);
}</pre>
<p>The !$row part is short for if ($row == false), which would be the case if no results were found in the database corresponding to the ID number we want.</p>
<p>We will close PHP now, so we can use HTML properly to display a form for a new category name.</p>
<pre>?&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;</pre>
<p>We will add a hidden field now. The value of the field will be the ID number of the category, so that the database knows which category this is when the form is submitted; the name of the field will be the section of the script we are in, which is edit_category. This will enable the script to know where we are once the form has submitted.</p>
<pre>&lt;p&gt;&lt;input type=&quot;hidden&quot; name=&quot;edit_category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt;</pre>
<p>Now we will show a field for entering a new category name, along with some text which tells us what the category is currently called.</p>
<pre>The current category name is &lt;?php echo $row['category_name']; ?&gt;. To change it, enter a new name in the box below.&lt;br /&gt;
Rename category to: &lt;input type=&quot;text&quot; name=&quot;new_name&quot; id=&quot;new_name&quot; /&gt;&lt;br /&gt;

&lt;input type=&quot;submit&quot; name=&quot;submit_category_edit&quot; id=&quot;submit_category_edit&quot; value=&quot;Submit new name&quot; /&gt;&lt;/p&gt;</pre>
<p>Finally for this part, we need to reopen PHP for the script to continue:</p>
<pre>&lt;?php</pre>
<p>We have now created our category editing form, but it is of no use without the processing part which we will do next.</p>
<p>Your edit category part should look like this:</p>
<pre>elseif (isset($_POST['edit_category'])) {

$category = (int)$_POST['category'];

if (empty($category)) {
die (&quot;No category chosen! Please go back and choose a category to edit.&quot;);
}

$result = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);
$row = mysql_fetch_array($result);

if (!$row) {
die(&quot;There doesn&#8217;t seem to be a category with the ID number submitted. Please go back and try again.&quot;);
}
?&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;

&lt;p&gt;&lt;input type=&quot;hidden&quot; name=&quot;edit_category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt;

The current category name is &lt;?php echo $row['category_name']; ?&gt;. To change it, enter a new name in the box below.&lt;br /&gt;

Rename category to: &lt;input type=&quot;text&quot; name=&quot;new_name&quot; id=&quot;new_name&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit_category_edit&quot; id=&quot;submit_category_edit&quot; value=&quot;Submit new name&quot; /&gt;&lt;/p&gt;

&lt;?php

}</pre>
<p>The next part will go ABOVE what we have just done. In other words, it will go underneath this line:</p>
<pre>elseif (isset($_POST['edit_category'])) {</pre>
<p>But above this one:</p>
<pre>$category = (int)$_POST['category'];</pre>
<p>What we will do now is check to see if the category has been renamed, and if it has, we will change it in the database. This is almost exactly the same process as the category addition section.</p>
<p>First we will check whether we have pressed to rename our category, or whether want to display the form to rename it (note that there is no closing brace on the end of this line, we will add this once we have finished processing the category).</p>
<pre>if (isset($_POST['submit_category_edit'])) {</pre>
<p>Now we check that the category name is appropriate, by stripping HTML and converting entities:</p>
<pre>$newcat = htmlspecialchars(strip_tags($_POST['new_name']));</pre>
<p>Next, we check to see if a category name was submitted:</p>
<pre>if (empty($newcat)) {
die(&quot;No new category name entered, please go back and try again.&quot;);
}</pre>
<p>Now we will check to see if a category ID was submitted, making sure it is numeric first.</p>
<pre>$id = (int)$_POST['edit_category'];

if (empty($id)) {
die(&quot;Invalid category!&quot;);
}</pre>
<p>Once we are sure we have all the parts we need, we need to update the category details in the database. However, we should escape any quotes first, as we did for the category addition part:</p>
<pre>if (!get_magic_quotes_gpc()) {
$newcat = mysql_real_escape_string($newcat);
}</pre>
<p>This is the code we shall use update the database:</p>
<pre>$edit = mysql_query(&quot;UPDATE php_blog_categories SET `category_name` = '$newcat' WHERE `category_id` = $id LIMIT 1&quot;);

if ($edit == true) echo 'Category successfully edited.';
else echo 'Category could not be edited. ' . mysql_error();</pre>
<p>The last thing we will do is to close the if statement we began earlier, to test whether we were updating the category or not. We do this by adding a closing brace.</p>
<pre>}</pre>
<p>We also need to separate the processing part from the editing form, otherwise we will have both happening at once. So we will add an else statement after the closing brace mentioned above, like so:</p>
<pre>else {</pre>
<p>And then a closing brace just before this line:</p>
<pre>elseif (isset($_POST['delete_category'])) {</pre>
<p>The complete edit block should look like this:</p>
<pre>elseif (isset($_POST['edit_category'])) {

if (isset($_POST['submit_category_edit'])) {

$newcat = htmlspecialchars(strip_tags($_POST['new_name']));

if (empty($newcat)) {
die(&quot;No new category name entered, please go back and try again.&quot;);
}

$id = (int)$_POST['edit_category'];

if (empty($id)) {
die(&quot;Invalid category!&quot;);
}

if (!get_magic_quotes_gpc()) {
$newcat = mysql_real_escape_string($newcat);
}

$edit = mysql_query(&quot;UPDATE php_blog_categories SET `category_name` = &#8216;$newcat&#8217; WHERE `category_id` = $id LIMIT 1&quot;);

if ($edit == true) echo &#8216;Category successfully edited.&#8217;;
else echo &#8216;Category could not be edited. &#8216; . mysql_error();

}
else {

$category = (int)$_POST['category'];

if (empty($category)) {
die (&quot;No category chosen! Please go back and choose a category to edit.&quot;);
}

$result = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);
$row = mysql_fetch_array($result);

if (!$row) {
die(&quot;There doesn&#8217;t seem to be a category with the ID number submitted. Please go back and try again.&quot;);
}
?&gt;

&lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
&lt;p&gt;&lt;input type=&quot;hidden&quot; name=&quot;edit_category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt;

The current category name is &lt;?php echo $row['category_name']; ?&gt;. To change it, enter a new name in the box below.&lt;br /&gt;
Rename category to: &lt;input type=&quot;text&quot; name=&quot;new_name&quot; id=&quot;new_name&quot; /&gt;&lt;br /&gt;

&lt;input type=&quot;submit&quot; name=&quot;submit_category_edit&quot; id=&quot;submit_category_edit&quot; value=&quot;Submit new name&quot; /&gt;&lt;/p&gt;
&lt;/form&gt;

&lt;?php

}

}</pre>
<p>And that&#8217;s the category management part done!</p>
<p>categories.php should look like this when completed:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');

if (isset($_POST['add_category'])) {

    $newcat = htmlspecialchars(strip_tags($_POST['new_category']));

    if (empty($newcat)) {
        die( &quot;No category submitted! Please go back and enter one.&quot;);
    }

    if (!get_magic_quotes_gpc()) {
        $newcat = mysql_real_escape_string($newcat);
    }

    $insert = mysql_query(&quot;INSERT INTO php_blog_categories (`category_name`) VALUES (&#8217;$newcat&#8217;)&quot;);

    if ($insert == true) echo &#8216;Category successfully added.&#8217;;
    else echo &#8216;The category could not be added to the database. &#8216; . mysql_error();

}
elseif (isset($_POST['edit_category'])) {

    if (isset($_POST['submit_category_edit'])) {

        $newcat = htmlspecialchars(strip_tags($_POST['new_name']));

        if (empty($newcat)) {
            die(&quot;No new category name entered, please go back and try again.&quot;);
        }

        $id = (int)$_POST['edit_category'];

        if (empty($id)) {
            die(&quot;Invalid category!&quot;);
        }

        if (!get_magic_quotes_gpc()) {
            $newcat = mysql_real_escape_string($newcat);
        }

        $edit = mysql_query(&quot;UPDATE php_blog_categories SET `category_name` = &#8216;$newcat&#8217; WHERE `category_id` = $id LIMIT 1&quot;);

        if ($edit == true) echo &#8216;Category successfully edited.&#8217;;
        else echo &#8216;Category could not be edited. &#8216; . mysql_error();

    }
    else {

        $category = (int)$_POST['category'];

        if (empty($category)) {
            die (&quot;No category chosen! Please go back and choose a category to edit.&quot;);
        }

        $result = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);
        $row = mysql_fetch_array($result);

        if (!$row) {
            die(&quot;There doesn&#8217;t seem to be a category with the ID number submitted. Please go back and try again.&quot;);
        }
        ?&gt;

        &lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
        &lt;p&gt;&lt;input type=&quot;hidden&quot; name=&quot;edit_category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt;

        The current category name is &lt;?php echo $row['category_name']; ?&gt;. To change it, enter a new name in the box below.&lt;br /&gt;
        Rename category to: &lt;input type=&quot;text&quot; name=&quot;new_name&quot; id=&quot;new_name&quot; /&gt;&lt;br /&gt;

        &lt;input type=&quot;submit&quot; name=&quot;submit_category_edit&quot; id=&quot;submit_category_edit&quot; value=&quot;Submit new name&quot; /&gt;&lt;/p&gt;
        &lt;/form&gt;

        &lt;?php

    }

}
elseif (isset($_POST['delete_category'])) {

    $category = (int)$_POST['category'];

    if (empty($category)) {
        die(&quot;No category chosen! Please go back and choose a category to delete.&quot;);
    }

    $delete = mysql_query(&quot;DELETE FROM php_blog_categories WHERE `category_id` = $category LIMIT 1&quot;);

    if ($delete == true) echo &#8216;Category successfully deleted.&#8217;;
    else echo &#8216;The category could not be deleted. &#8216; . mysql_error();

}
else {

    $result = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);
    ?&gt;
    &lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;&lt;p&gt;

    &lt;?php
    while($row = mysql_fetch_array($result)) {
        ?&gt;

        &lt;input type=&quot;radio&quot; name=&quot;category&quot; value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot; /&gt; &lt;?php echo $row['category_name']; ?&gt;&lt;br /&gt;

        &lt;?php
    }
    ?&gt;

    &lt;/p&gt;
    &lt;p&gt;&lt;input type=&quot;submit&quot; name=&quot;edit_category&quot; id=&quot;edit_category&quot; value=&quot;Edit selected category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;delete_category&quot; id=&quot;delete_category&quot; value=&quot;Delete selected category&quot; /&gt;&lt;/p&gt;

    &lt;/form&gt;

    &lt;form action=&quot;categories.php&quot; method=&quot;post&quot;&gt;
    &lt;p&gt;Add new category: &lt;input type=&quot;text&quot; name=&quot;new_category&quot; id=&quot;new_category&quot; /&gt; &lt;input type=&quot;submit&quot; name=&quot;add_category&quot; id=&quot;add_category&quot; value=&quot;Add category&quot; /&gt;&lt;/p&gt;

    &lt;/form&gt;

    &lt;?php
}

mysql_close();
?&gt;</pre>
</li>
<li>
<p>Now we need to implement categories into our new post and edit post pages. We will start with the new post page.</p>
<p>Find the following part in your entry posting page:</p>
<pre>&lt;p&gt;&lt;strong&gt;&lt;label for=&quot;title&quot;&gt;Title:&lt;/label&gt;&lt;/strong&gt; &lt;input type=&quot;text&quot; name=&quot;title&quot; id=&quot;title&quot; size=&quot;40&quot; /&gt;&lt;/p&gt;</pre>
<p>Above that, we will add our category selection box. By default this may look slightly odd on your page, especially if you have a long category name, but you can easily change this using CSS.</p>
<p>We will start by getting our categories from the database. We don&#8217;t have a database connection on this page yet, so we will insert one here:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password');
mysql_select_db('db_name');</pre>
<p>Let&#8217;s select the categories and display them in a loop:</p>
<pre>$result = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);

echo '&lt;p&gt;&lt;strong&gt;&lt;label for=&quot;category&quot;&gt;Category:&lt;/label&gt;&lt;/strong&gt; &lt;select name=&quot;category&quot; id=&quot;category&quot;&gt;';

while($row = mysql_fetch_array($result)) { ?&gt;

&lt;option value=&quot;&lt;?php echo $row['category_id']; ?&gt;&quot;&gt;&lt;?php echo $row['category_name']; ?&gt;&lt;/option&gt;

&lt;?php
}
?&gt;

&lt;/select&gt;&lt;/p&gt;</pre>
<p>Now find this part in your post page:</p>
<pre>$entry = nl2br($entry);</pre>
<p>Above that, we will add our category processing, and we will make sure it&#8217;s a number (category ID):</p>
<pre>$category = (int)$_POST['category'];</pre>
<p>Next find this:</p>
<pre>$sql = &quot;INSERT INTO php_blog (timestamp,title,entry) VALUES ('$timestamp','$title','$entry')&quot;;</pre>
<p>(This may look slightly different if you have password protection or custom fields enabled)</p>
<p>You need to add the category field to this query.</p>
<pre>$sql = &quot;INSERT INTO php_blog (timestamp,title,entry,category) VALUES ('$timestamp','$title','$entry','$category')&quot;;</pre>
</li>
<li>
<p>Now that we have added the category to new posts, we need to be able to add it to our edit posts page as well, so we can change the category if needs be.</p>
<p><strong>Please note that you can only have ONE category per entry. This tutorial will not teach you how to give your entries multiple categories (or &quot;tags&quot;).</strong></p>
<p>In your update entry page, find the following code:</p>
<pre>$old_timestamp = $row['timestamp'];
$old_title = stripslashes($row['title']);
$old_entry = stripslashes($row['entry']);
$old_password = $row['password'];</pre>
<p>Add this part to the end:</p>
<pre>$old_category = $row['category'];</pre>
<p>Next, find this part:</p>
<pre>&lt;p&gt;&lt;strong&gt;&lt;label for=&quot;title&quot;&gt;Title:&lt;/label&gt;&lt;/strong&gt; &lt;input type=&quot;text&quot; name=&quot;title&quot; id=&quot;title&quot; value=&quot;&lt;?php echo $old_title; ?&gt;&quot; size=&quot;40&quot; /&gt;&lt;/p&gt;</pre>
<p>Above that, we will add our categories just like we did to the post entry form. We don&#8217;t need to open a database connection since we already have one, so we will get straight to it. However, we need to make sure the current category of the entry is selected; we will do this by testing each category to see if it matches the category ID stored for that post. If it matches, we will insert the proper HTML to select the current category by default.</p>
<p>Here is the code for the categories:</p>
<pre>&lt;?php
$result2 = mysql_query(&quot;SELECT * FROM php_blog_categories&quot;);

echo '&lt;p&gt;&lt;strong&gt;&lt;label for=&quot;category&quot;&gt;Category:&lt;/label&gt;&lt;/strong&gt; &lt;select name=&quot;category&quot; id=&quot;category&quot;&gt;';

while($row2 = mysql_fetch_array($result2)) { ?&gt;

    &lt;option value=&quot;&lt;?php echo $row2['category_id']; ?&gt;&quot; &lt;?php if ($old_category == $row2['category_id']) echo &#8216; selected=&quot;selected&quot;&#8217;; ?&gt;&gt;&lt;?php echo $row2['category_name']; ?&gt;&lt;/option&gt;
    &lt;?php
}
?&gt;
&lt;/select&gt;&lt;/p&gt;</pre>
<p>We need to call this $row2 and $result2 rather than our normal $result and $row, since we already have a $result and $row - those are related to the entry (not the categories), and we don&#8217;t want to overwrite them.</p>
<p>Now we must process the category update. This is identical to what we did to process the category in the new post page - first we look for this part in the code:</p>
<pre>$entry = nl2br($entry);</pre>
<p>Underneath it, we add:</p>
<pre>$category = (int)$_POST['category'];</pre>
<p>Now is where it differs slightly. Find this part:</p>
<pre>$result = mysql_query(&quot;UPDATE php_blog SET timestamp='$timestamp', title='$title', entry='$entry', password='$password' WHERE id='$id' LIMIT 1&quot;) or print (&quot;Can't update entry.&lt;br /&gt;&quot; . mysql_error());</pre>
<p>(Again, this will differ depending on which fields you have in your database, and whether you are using password protection or not)</p>
<p>Let&#8217;s add the category update to that query:</p>
<pre>$result = mysql_query(&quot;UPDATE php_blog SET timestamp='$timestamp', title='$title', entry='$entry', password='$password', category='$category' WHERE id='$id' LIMIT 1&quot;) or print (&quot;Can't update entry.&lt;br /&gt;&quot; . mysql_error());</pre>
<p>And we&#8217;re done!</p>
</li>
<li>But of course we&#8217;re not completely done yet - we want to show the category of a post on our blog front page, and on an individual entry.
<p>To do this, find this part in both your main blog page and your individual entry page (it will appear several times in your individual entry page, and again will look different depending on the fields you have):</p>
<pre>    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $password = $row['password'];</pre>
<p>Underneath this, we need to get our categories. We have them stored by ID in the entries table, so we need to convert them to their names.</p>
<p>To do this, we need to get the name from the categories table, using the ID stored in the entries table, like so:</p>
<pre>$get_categories = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE `category_id` = $row[category]&quot;);
$category = mysql_fetch_array($get_categories);</pre>
<p>Now we are ready to display the category. Find these parts in your blog and individual entry pages (again, this may appear several times:</p>
<pre>&lt;p&gt;&lt;strong&gt;&lt;?php echo $title; ?&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
        &lt;?php echo $entry; ?&gt;&lt;br /&gt;&lt;br /&gt;

        Posted on &lt;?php echo $date; ?&gt;&lt;/p&gt;</pre>
<p>Just add the category where you want it to show up. For example:</p>
<pre>&lt;p&gt;&lt;strong&gt;&lt;?php echo $title; ?&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
        &lt;?php echo $entry; ?&gt;&lt;br /&gt;&lt;br /&gt;

        Posted in &lt;?php echo $category['category_name']; ?&gt; on &lt;?php echo $date; ?&gt;&lt;/p&gt;</pre>
</li>
<li>&#8230;You probably want to show all the posts in one category now, don&#8217;t you? Well if you do, you can change the code above to link the category to its archives, like so:
<pre>Posted in &lt;a href=&quot;category.php?category=&lt;?php echo $row['category']; ?&gt;&quot;&gt;&lt;?php echo $category['category_name']; ?&gt;&lt;/a&gt; on &lt;?php echo $date; ?&gt;</pre>
<p>We will now make a category archive page, which will look pretty much exactly like the yearly archive page. We will call this page category.php (note that this is different from your category admin page, which is called <strong>categories.php</strong>. You can of course rename these files to anything you like, but in this example I will use category.php as the category archive page.</p>
<p>Let&#8217;s start with the MySQL connection:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password') ;
mysql_select_db('db_name');</pre>
<p>We now need to check what category we are displaying, which is decided by the ?category= part in the URL. If someone has gone directly to category.php without specifying a category to display, we need to display an error just like we do in the single entry page and the archive page, when the person hasn&#8217;t specified a year or entry ID to look at.</p>
<pre>if (!isset($_GET['category'])) {
    die(&quot;Invalid category specified.&quot;);
}
else {
    $category = (int)$_GET['category'];
}</pre>
<p>Now that we have the category we want to display entries from, let&#8217;s collect the posts from the entries table:</p>
<pre>$result = mysql_query(&quot;SELECT timestamp, id, title FROM php_blog WHERE category = $category ORDER BY id DESC&quot;);</pre>
<p>We will now add up how many posts were found:</p>
<pre>$num = mysql_num_rows($result);</pre>
<p>&#8230;and get the category name from the categories table:</p>
<pre>$get_category = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE category_id = $category&quot;);
$get_category2 = mysql_fetch_array($get_category);</pre>
<p>Now we can use those details as a header, for example you might want to say something like this:</p>
<pre>echo &quot;&lt;h1&gt;There are $num posts in the &amp;quot;$get_category2[category_name]&amp;quot;category&lt;/h1&gt;&quot;</pre>
<p>Let&#8217;s now show the posts. This is identical to the archive page entry code.</p>
<pre>while ($row = mysql_fetch_array($result)) {
    $date = date(&quot;l F d Y&quot;, $row['timestamp']);
    $id = $row['id'];
    $title = stripslashes($row['title']);

    ?&gt;

    &lt;p&gt;&lt;?php echo $date; ?&gt;&lt;br /&gt;&lt;a href=&quot;journal.php?id=&lt;?php echo $id; ?&gt;&quot;&gt;&lt;?php echo $title; ?&gt;&lt;/a&gt;&lt;/p&gt;

    &lt;?php
}

?&gt;</pre>
<p>That&#8217;s the category archive done. The complete code should look like this:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password') ;
mysql_select_db('db_name');

if (!isset($_GET['category'])) {
    die(&quot;Invalid category specified.&quot;);
}
else {
    $category = (int)$_GET['category'];
}

$result = mysql_query(&quot;SELECT timestamp, id, title FROM php_blog WHERE category = $category ORDER BY id DESC&quot;);

$num = mysql_num_rows($result);

$get_category = mysql_query(&quot;SELECT * FROM php_blog_categories WHERE category_id = $category&quot;);
$get_category2 = mysql_fetch_array($get_category);

echo &quot;&lt;h1&gt;There are $num posts in the &amp;quot;$get_category2[category_name]&amp;quot;category&lt;/h1&gt;&quot;;

while($row = mysql_fetch_array($result)) {
    $date = date(&quot;l F d Y&quot;, $row['timestamp']);
    $id = $row['id'];
    $title = stripslashes($row['title']);

    ?&gt;

    &lt;p&gt;&lt;?php echo $date; ?&gt;&lt;br /&gt;&lt;a href=&quot;journal.php?id=&lt;?php echo $id; ?&gt;&quot;&gt;&lt;?php echo $title; ?&gt;&lt;/a&gt;&lt;/p&gt;
    &lt;?php
}

?&gt;</pre>
</li>
<li>
<p>You may want a little block to display all your categories and the number of posts in them, just like for the yearly archives. If you&#8217;d like to do this, here is how.</p>
<p>First, let&#8217;s connect to the database:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password') ;
mysql_select_db('db_name');</pre>
<p>Next, let&#8217;s get our categories from the database:</p>
<pre>$result1 = mysql_query(&quot;SELECT * FROM php_blog_categories ORDER BY category_name ASC&quot;);</pre>
<p>Now let&#8217;s display the categories and link them to the archives:</p>
<pre>while($row = mysql_fetch_array($result1)) {</pre>
<p>Ah, before we can do that, we need our posts! We need to get them while inside the loop, as we need a different post count for each category.</p>
<pre>$result2 = mysql_query(&quot;SELECT COUNT(`id`) AS entries FROM php_blog WHERE category = $row[category_id]&quot;);
$num_entries = mysql_fetch_array($result2);</pre>
<p><em>Now</em> we can proceed with showing the posts!</p>
<pre>    echo '&lt;a href=&quot;category.php?category=' . $row['category_id'] . &#8216;&quot;&gt;&#8217; . $row['category_name'] . &#8216;&lt;/a&gt; (&#8217; . $num_entries['entries'] . &#8216;)&lt;br /&gt;&#8217;;</pre>
<p>Let&#8217;s close that while loop and PHP in general:</p>
<pre>}
?&gt;</pre>
<p>Your category archive block should look like this:</p>
<pre>&lt;?php
mysql_connect('localhost', 'db_username', 'db_password') ;
mysql_select_db('db_name');

$result1 = mysql_query(&quot;SELECT * FROM php_blog_categories ORDER BY category_name ASC&quot;);

while($row = mysql_fetch_array($result1)) {

    $result2 = mysql_query(&quot;SELECT COUNT(`id`) AS entries FROM php_blog WHERE category = $row[category_id]&quot;);
    $num_entries = mysql_fetch_array($result2);

    echo &#8216;&lt;a href=&quot;category.php?category=&#8217; . $row['category_id'] . &#8216;&quot;&gt;&#8217; . $row['category_name'] . &#8216;&lt;/a&gt; (&#8217; . $num_entries['entries'] . &#8216;)&lt;br /&gt;&#8217;;

}
?&gt;</pre>
</li>
</ol>
<p>And that&#8217;s it! Now you should have categories fully enabled in your blog!</p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/tutorials/part-11-categories/feed</wfw:commentRss>
		</item>
		<item>
		<title>NL-PHPMail 2.2 released</title>
		<link>http://codegrrl.com/updates/nl-phpmail-22-released</link>
		<comments>http://codegrrl.com/updates/nl-phpmail-22-released#comments</comments>
		<pubDate>Fri, 02 Mar 2007 17:33:35 +0000</pubDate>
		<dc:creator>Amelie</dc:creator>
		
		<category><![CDATA[Scripts]]></category>

		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=171</guid>
		<description><![CDATA[NL-PHPMail 2.2 has been released. This version contains the following updates:

Improved header injection protection
Improved captcha
Better error handling
Easier customization
Double-escaped entities in received emails now fixed

All users of NL-PHPMail are advised to upgrade in order to fully protect against header injection. 
]]></description>
			<content:encoded><![CDATA[<p>NL-PHPMail 2.2 has been released. This version contains the following updates:</p>
<ul>
<li>Improved header injection protection</li>
<li>Improved captcha</li>
<li>Better error handling</li>
<li>Easier customization</li>
<li>Double-escaped entities in received emails now fixed</li>
</ul>
<p>All users of NL-PHPMail are advised to upgrade in order to fully protect against header injection. <img src='http://codegrrl.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/updates/nl-phpmail-22-released/feed</wfw:commentRss>
		</item>
		<item>
		<title>CodeGrrl Moved</title>
		<link>http://codegrrl.com/updates/codegrrl-moved</link>
		<comments>http://codegrrl.com/updates/codegrrl-moved#comments</comments>
		<pubDate>Sun, 20 Aug 2006 17:31:00 +0000</pubDate>
		<dc:creator>Sasha</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=170</guid>
		<description><![CDATA[Just to let everyone know, I have moved CodeGrrl to a new server tonight. We are now hosted by Dreamhost. Over the past 6 months or so, visitors have been increasing steadily, and the old server just wasn&#8217;t coping with the load from the forums very well anymore.
The move went pretty smoothly, I am just [...]]]></description>
			<content:encoded><![CDATA[<p>Just to let everyone know, I have moved CodeGrrl to a new server tonight. We are now hosted by Dreamhost. Over the past 6 months or so, visitors have been increasing steadily, and the old server just wasn&#8217;t coping with the load from the forums very well anymore.</p>
<p>The move went pretty smoothly, I am just now fixing the last few bugs in the forums. The MySQL database I moved over was 88MB in size - the vast majority of it caused by the forums! Anyway, I think everything is pretty much back up and running, but please let me know if you spot any errors anywhere.</p>
<p>Hopefully our new location will provide us with faster page loading and less downtime!</p>
]]></content:encoded>
			<wfw:commentRss>http://codegrrl.com/updates/codegrrl-moved/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
