/    Sign up×
Community /Pin to ProfileBookmark

using $_Get to run a query

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>”; ?>[/code]

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
}

?>[/code]

Any help is greatly appriciated.
Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@themartyJul 05.2006 — well, apparently

!isset($_GET['category']) => it is not set (typo in the url?)

|| => OR

!is_numeric($_
GET['category']) => it is set, but not a number

the only way to find out is to echo $_GET['category']

debugging in it's simplest form....
Copy linkTweet thisAlerts:
@bokehJul 05.2006 — Works for me.
Copy linkTweet thisAlerts:
@MegatronauthorJul 06.2006 — cheers for looking over the code. I got it working by using

if (!isset($_GET['category']) || is_numeric($_GET['category']))

{

//stuff

}


!is_numeric($_GET['category']);
×

Success!

Help @Megatron spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...