woolyg Posted May 11, 2007 Share Posted May 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/ Share on other sites More sharing options...
genericnumber1 Posted May 11, 2007 Share Posted May 11, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/#findComment-250275 Share on other sites More sharing options...
woolyg Posted May 11, 2007 Author Share Posted May 11, 2007 Thanks for that - much obliged. -Woolyg. Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/#findComment-250301 Share on other sites More sharing options...
woolyg Posted May 11, 2007 Author Share Posted May 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/#findComment-250394 Share on other sites More sharing options...
genericnumber1 Posted May 11, 2007 Share Posted May 11, 2007 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/#findComment-250626 Share on other sites More sharing options...
woolyg Posted May 11, 2007 Author Share Posted May 11, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/#findComment-250921 Share on other sites More sharing options...
black.horizons Posted May 11, 2007 Share Posted May 11, 2007 just have an if statement checking that the categoryid is not null if($categoryid != "") { .. } else { echo "oi ye git enter a value!"; } Quote Link to comment https://forums.phpfreaks.com/topic/50885-get-issue-im-get-ing-haw-haw/#findComment-250933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.