spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / practical_php_mysql4

[next]

Managed Services Subject Matter Expert (PA)
Next Step Systems
US-PA-Wayne

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies


Building a Weblog: Part 4

By Jono Bacon

Rolling Your Own Categories

Adding blog categories is the next part of the game. This page is similar to the page used to add comments.

First, create the form in a new file called addcat.php:

Add the usual lines of code at the start of the file, before any HTML:

With this page available to restricted users only, you need to check if the user is logged in. Do this by checking if one of the session variables exists; if it doesn't, redirect to another page:

NOTE

Never Assume

It might seem impossible to get to this page without clicking a link, and wouldn't that imply the user has already logged in? Although this sounds logical, someone could still type the URL directly. It's always better to explicitly check to ensure the user is logged in, rather than trust other pages to do that job for you.


Add the logic for when the user clicks the Submit button:

Within this code, an INSERT query is created and sent to the database. After the query is run, the browser redirects to the viewcat.php page to view the newly created category.

Finally, close the else and include the footer.php file (all after the form):

home / programming / practical_php_mysql4

[next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji

URL: