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