Dragen Posted April 29, 2007 Share Posted April 29, 2007 Okay, I've got this extremly simple code: $feed = $_GET['feed']; The problem is there isn't always a feed variable to get when the page loads so I recieve a: Notice: Undefined index: feed in /home/fhlinux172/t/test.gimppro.co.uk/user/htdocs/littleoaks/feedback.php on line 2 So every time I load the page it gives me this error... Is there any way of stopping this error if there is no feed variable to get using $_GET? Thanks Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/ Share on other sites More sharing options...
the_oliver Posted April 29, 2007 Share Posted April 29, 2007 try: if ($_GET['feed'] > "") { $feed = $_GET['feed']; } Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/#findComment-241247 Share on other sites More sharing options...
utexas_pjm Posted April 29, 2007 Share Posted April 29, 2007 <?php if (isset($_GET['feed'])) { $feed = $_GET['feed'] } ?> Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/#findComment-241249 Share on other sites More sharing options...
Dragen Posted April 29, 2007 Author Share Posted April 29, 2007 you missed out the ; after $_GET['feed'].. but I still get the same message. The problem is I'm checking for 'feed' using get, but if there is no 'feed' sent, then I recieve the error telling me that it's looking for something that isn't there.... I've never had this problem on my usual server, but have just set up a new one that I use for testing scripts. I think it must have some different settings for warnings etc.. EDIT: utexas! thanks. the isset worked. Thanks. Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/#findComment-241251 Share on other sites More sharing options...
the_oliver Posted April 29, 2007 Share Posted April 29, 2007 Strange. Try running a script with only <?php phpinfo() ?> and see if anything strange comes up. Or compare it to your other server. Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/#findComment-241252 Share on other sites More sharing options...
utexas_pjm Posted April 29, 2007 Share Posted April 29, 2007 Just FYI, it seems that your error reporting is set to E_ALL. Most of the time people ignore E_NOTICE's you can do so by setting your error handling to E_ALL ^ E_NOTICE. You can read more about it here: http://php.net/error_reporting. Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/#findComment-241253 Share on other sites More sharing options...
Dragen Posted April 29, 2007 Author Share Posted April 29, 2007 hmm.. didn't realise I could do that. To be honest though I didn't have a clue what half of it meant. I've got it solved now though. Just needed to use isset! EDIT: Thanks utexas. i thought it might be something to do with error reporting, but don't know much about it. Link to comment https://forums.phpfreaks.com/topic/49234-solved-variable-not-always-set-so-i-recieve-an-error/#findComment-241254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.