Help - Search - Members - Calendar
Full Version: Build a Blog: Showing Categories
Codegrrl.com Forums > Script Help > Tutorial Help
Aveline
I have used the individual entry code to try and create my categories. I'm just confused as to what I should use instead of is_numeric since the categories aren't numbered.

Or should I be using a completely different code altogether?

CODE
<?php
mysql_connect ('localhost', '', '');
mysql_select_db ('');

if (!isset($_GET['category']) || !is_numeric($_GET['category'])) {
    die("Invalid category specified.");
}

$id = (int)$_GET['category'];

$sql = "SELECT * FROM php_blog WHERE cat='$category' LIMIT 99";

$result = mysql_query($sql) or print ("Can't select entry from table php_blog.<br />" . $sql . "<br />" . mysql_error());

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

    $date = date("d F Y", $row['timestamp']);

    $title = stripslashes($row['title']);
    $id = stripslashes($row['id']);
    $summary = stripslashes($row['summary']);
    $category = stripslashes($row['category']);
    $entry = stripslashes($row['entry']);

    ?>

    <a href="read.php?id=<?php echo $id; ?>"><?php echo $title; ?></a><p />
    <?php echo $summary; ?><p />
    Posted on <?php echo $date; ?> | In Category <a href="show.php?cat=<?php echo $category; ?>"><?php echo $category; ?></a><p />

    <?php
}

?>
loadx
if it's not numeric then make the if statement only check $_GET['category'] is set.

i.e
CODE

if (!isset($_GET['category']) ){
Aveline
Thank you, I have tried it but now I'm getting the message 'Invalid category specified'.
Amelie
You need to go to category.php?category=categoryname. Going to category.php by itself won't work.

Also, you need to change this line:

CODE
$id = (int)$_GET['category'];


To this:

CODE
$category = htmlspecialchars($_GET['category']);
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.