spacer

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

home / programming / practical_php_mysql4

[next]

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

URL: