Jump to content

GET issue I'm 'GET'-ing... haw haw:)


woolyg

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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

Hi,

 

Is there a way I can utilise the variables

 

echo $row['id'];

echo $row['categoryid'];

echo $row['question'];

echo $row['answer'];

 

past the closing '}'?

 

each time I try, I get an undefined index error..

Link to comment
Share on other sites

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.