spacer

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

home / programming / practical_php_mysql4

[next]

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


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 >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

URL: