mistypotato Posted August 12, 2008 Share Posted August 12, 2008 Hello, Should this work?.... if ($ncvx) $ncustid = 0; else $ncustid = $_GET['ncvx']; thx Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/ Share on other sites More sharing options...
cdog5000 Posted August 12, 2008 Share Posted August 12, 2008 Hello, Should this work?.... if ($ncvx) $ncustid = 0; else $ncustid = $_GET['ncvx']; thanks if (!$ncvx) $ncustid = 0; else $ncustid = $_GET['ncvx']; try that Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614217 Share on other sites More sharing options...
monkeypaw201 Posted August 12, 2008 Share Posted August 12, 2008 No, try this: <?php if (isset($_GET['ncvx'])) { $ncustid = 0; }else{ $ncustid = $_GET['ncvx']; } ?> I assume, you want to check if its passed in the URL? Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614218 Share on other sites More sharing options...
mistypotato Posted August 12, 2008 Author Share Posted August 12, 2008 Thanks for the kwik help cdog & monkeypaw ! cdog, i get an error with your code :-( Monkeypaw, with your code, the error is gone, but the value does not seem to be returned? any suggestions ? thx ! Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614224 Share on other sites More sharing options...
monkeypaw201 Posted August 12, 2008 Share Posted August 12, 2008 Thanks for the kwik help cdog & monkeypaw ! cdog, i get an error with your code :-( Monkeypaw, with your code, the error is gone, but the value does not seem to be returned? any suggestions ? thanks ! I assume, you want to check if the variable ncvx is passed in the URL? (ie http://my.domain.com/page.php?ncvx=something) if so, try this: <?php if(isset($_GET['ncvx'])) { $ncustid = 0; }else{ $ncustid = $_GET['ncvx']; } ?> otherwise, please elaborate.. Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614227 Share on other sites More sharing options...
mistypotato Posted August 12, 2008 Author Share Posted August 12, 2008 Hi monkeypaw, yes, you are correct. I want to check for the existence of the variable in the URL just as you describe. Problem is, the function you wrote for some reason does not return the value if it does exist in the URL unless I add this after your code like this... which defeats the purpose of course :-) if (isset($_GET['ncvx'])) { $ncustid = 0; }else{ $ncustid = $_GET['ncvx']; } $ncustid = $_GET['ncvx']; it's as though the first part works correctly but it ignores the section AFTER the else even if there IS a value in the URL Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614232 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 I want to get in on this! <?php $ncustid = (empty($_GET['ncvx'])) ? 0 : $_GET['ncvx']; ?> Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614236 Share on other sites More sharing options...
monkeypaw201 Posted August 12, 2008 Share Posted August 12, 2008 Hi monkeypaw, yes, you are correct. I want to check for the existence of the variable in the URL just as you describe. Problem is, the function you wrote for some reason does not return the value if it does exist in the URL unless I add this after your code like this... which defeats the purpose of course :-) if (isset($_GET['ncvx'])) { $ncustid = 0; }else{ $ncustid = $_GET['ncvx']; } $ncustid = $_GET['ncvx']; it's as though the first part works correctly but it ignores the section AFTER the else even if there IS a value in the URL oops, my mistake! i reversed things.. this should work: if (isset($_GET['ncvx'])) { $ncustid = $_GET['ncvx']; }else{ $ncustid = 0; } Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614238 Share on other sites More sharing options...
tibberous Posted August 12, 2008 Share Posted August 12, 2008 <?php $ncustid = ($_GET['ncvx']) ? 0 : $_GET['ncvx']; ?> Just as good. I hate people who use isset and empty. Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614239 Share on other sites More sharing options...
mistypotato Posted August 12, 2008 Author Share Posted August 12, 2008 OMG Generic ! That worked perfectly !!!! MANY MANY thanks to all of you you're great Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614240 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 Pft tibberous, what if $_GET['ncvx'] is the string 'false'? EDIT: example... <?php $var = 'false'; echo isset($var) == true; // true echo !empty($var) == true; // true echo $var == true; // false ?> There IS an advantage to using empty() or isset() over not using anything. Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614243 Share on other sites More sharing options...
monkeypaw201 Posted August 12, 2008 Share Posted August 12, 2008 <?php $ncustid = ($_GET['ncvx']) ? 0 : $_GET['ncvx']; ?> Just as good. I hate people who use isset and empty. Somtimes, the simplest ways are the best (BTW don't diss just because you code differently) Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614244 Share on other sites More sharing options...
mistypotato Posted August 12, 2008 Author Share Posted August 12, 2008 Really, thank you all for the fast help ! I had no idea I could get this resolved this evening...so quickly You've all made my night and especially you Generic. You guys really know this stuff ;-) Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614247 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 If only all questions could be answered so easily. Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614248 Share on other sites More sharing options...
tibberous Posted August 12, 2008 Share Posted August 12, 2008 Pft tibberous, what if $_GET['ncvx'] is the string 'false'? EDIT: example... <?php $var = 'false'; echo isset($var) == true; // true echo !empty($var) == true; // true echo $var == true; // false ?> There IS an advantage to using empty() or isset() over not using anything. I didn't say it was the same, just that it was 'just as good'. How does someone use the string 'false'? Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614251 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 I didn't say it was the same, just that it was 'just as good'. How does someone use the string 'false'? a true/false questionaire? o.O Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614252 Share on other sites More sharing options...
tibberous Posted August 12, 2008 Share Posted August 12, 2008 Then your way would have 'false'==true, it would screw it up =) Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614254 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 no, my way is empty() !empty('false') == true evaluates to true == true evaluates to true your way is 'false' == true evaluates to false == true evaluates to false you could rectify by doing $str === true for everything, but that's even worse than using empty() edit: spelling I'm just saying using $str instead of !empty($str) does not work 100% of the time, plus it looks messier (to me) Link to comment https://forums.phpfreaks.com/topic/119248-empty-variable-check/#findComment-614255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.