On a previous php page i have this line of code:
[code=php]Posted in the <?php echo “<a href=”category.php?category=” . $category . “”>$category</a>”; ?>
which passes the variable $category to the page category.php. I’m trying to use the code below to take in the variable and run a query on it but i’m not getting past my first statement. I get a “Invalid ID specified” error returned from my error checker.
[code=php]<?php
include ‘db.php’;
if (!isset($_GET[‘category’]) || !is_numeric($_GET[‘category’])) {
die(“Invalid ID specified.”);
}
$category = (int)$_GET[‘category’];
$sql = “SELECT * FROM php_blog WHERE category=’$category’ LIMIT 1”;
$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(“l F d Y”, $row[‘timestamp’]);
$title = stripslashes($row[‘title’]);
$entry = stripslashes($row[‘entry’]);
?>
<p><strong><?php echo $title; ?></strong><br /><br />
<?php echo $entry; ?><br /><br />
Posted on <?php echo $date; ?></p>
<?php
}
?>
Any help is greatly appriciated.
Thanks