Jump to content

empty variable check


mistypotato

Recommended Posts

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

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

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

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

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

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

 

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

Archived

This topic is now archived and is closed to further replies.

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