Jump to content

[SOLVED] Little Problem


S A N T A

Recommended Posts

Ok so i am working on a blog from scratch and so far its going good but now I'm working on an archive and i got everything working but when i click a category it is suppose to display all the entries in that category but the page stays the same?

 

heres the code:

 

<?php

require("config.php");
require("header.php");

?>
<div id="main">

<?php

if(isset($_GET['id']) == TRUE) {
if(is_numeric($id) == FALSE) {
	$error = 1;
}
if($error == 1) {

}
else {
	$validcat = $_GET['id'];
}
}
else {
$validcat = 0;
}

$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);
$sql = "SELECT * FROM categories";
$result = mysql_query($sql);




while($row = mysql_fetch_assoc($result)) {
if($validcat == $row['id']) {
	echo "<strong>" . $row['cat'] . "</strong><br />";

	$entriessql = "SELECT * FROM entries WHERE cat_id = " . $validcat . " ORDER BY dateposted DESC;";

	$entriesres = mysql_query($entriessql)or die(mysql_error(). "   in $sql");
	$numrows_entries = mysql_num_rows($entriesres);

	echo "<ul>";
	if($numrows_entries == 0) {
		echo "<li>No entries!</li>";
	}
	else {
		while($entriesrow = mysql_fetch_assoc($entriesres)) {
			echo "<li>" . date("D jS F Y g.iA", strtotime($entriesrow['dateposted'])) . " - <a href='viewentry.php?id=" . $entriesrow['id'] . "'>" . $entriesrow['subject'] . "</a></li>";
		}
	}
	echo "</ul>";
}
else {
	echo "<a href='viewcat.php?id=" . $row['id'] . "'>" . $row['cat'] . "</a><br />";
	}
}

require("footer.php");
?>
</div>

 

Help NEEDED

Link to comment
https://forums.phpfreaks.com/topic/103191-solved-little-problem/
Share on other sites

shouldn't

if(is_numeric($id) == FALSE) {

be

if(is_numeric($_GET['id']) == FALSE) {

 

EDIT:

<?php
if(isset($_GET['id']) == TRUE) {
if(is_numeric($id) == FALSE) {
	$error = 1;
}
if($error == 1) {

}
else {
	$validcat = $_GET['id'];
}
}
else {
$validcat = 0;
}
?>

 

revised

<?php
$validcat = (!empty($_GET['id']))?(int)$_GET['id']:0;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.