Jump to content

Recommended Posts

Hi all,

 

I'd like to be able to display mypage.php?categoryid=1, and I got that working ok. However, when I now try to just go to mypage.php on its own, I get an error (supplied argument is not a valid mySQL resource). Here's the code:

 

if(isset($_GET['categoryid']) && !empty($_GET['categoryid'])){
$q = "SELECT * FROM `doc_content` WHERE `categoryid`=".$_GET['categoryid'];
$r = mysql_query($q);
$categoryid = $_GET['categoryid'];
}
while($row = mysql_fetch_array($r)){
echo $row['id'];
echo $row['categoryid'];
echo $row['question'];
echo $row['answer'];
}

 

..do I need to add something in for the standard page to display normally?

Wooly

Link to comment
https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/
Share on other sites

<?php
if(isset($_GET['categoryid']) && !empty($_GET['categoryid'])){
$q = "SELECT * FROM `doc_content` WHERE `categoryid`=".$_GET['categoryid'];
$r = mysql_query($q);
$categoryid = $_GET['categoryid'];

while($row = mysql_fetch_array($r)) {
	echo $row['id'];
	echo $row['categoryid'];
	echo $row['question'];
	echo $row['answer'];
}
}
?>

 

this script is vulnerable to sql injection as well

Bah!! I managed to break it again..

 

I'm using the code

<?php
$q = "SELECT `id`,`question`,`answer`,UNIX_TIMESTAMP(`last_updated`) 'last_updated' FROM `doc_content` WHERE `categoryid` = ".$_GET['categoryid']." ORDER BY `last_updated` ASC";
$r = mysql_query($q,$db) or die(mysql_error());
$n = mysql_num_rows($r);
?>

 

which works fine when I want to view mypage.php?categoryid=1, but when I try to view simply mypage.php i get the error:

 

Undefined index: categoryid

 

 

can anyone help? How can I view mypage.php without error, while also being able to view mypage.php?categoryid=1  ???

 

Cheers,

Woolyg

you need to make sure $_GET['categoryid'] is set.... use the same technique as before...

 

<?php
if(isset($_GET['categoryid']) && !empty($_GET['categoryid'])){
    $q = "SELECT `id`,`question`,`answer`,UNIX_TIMESTAMP(`last_updated`) 'last_updated' FROM `doc_content` WHERE `categoryid` = ".$_GET['categoryid']." ORDER BY `last_updated` ASC";
    $r = mysql_query($q,$db) or die(mysql_error());
    $n = mysql_num_rows($r);
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.