Re: [PHP] isset empty or ...?

2013-03-31 Thread Александр Меньщиков
http://www.php.net/manual/en/types.comparisons.php
Maybe first table PHP functions comparison (including 'isset' and 'empty') 
could help you.


31.03.2013 в 8:53, John Taylor-Johnston написал(а):
> I'm using

if($mydata->>DPRresponselocationaddress1 != "")

> is this the same as

if (!isset($mydata->>DPRresponselocationaddress))
> http://php.net/manual/en/function.isset.php

> or

if (!empty($mydata->>DPRresponselocationaddress))
> http://php.net/manual/en/function.empty.php

> or is there another function I have not learned yet? I don't really get 
> the difference between isset and empty.

> John



-- 
С уважением, Александр Меньщиков

Тел.: +7 921 408-6-777
E-mail: amenshchi...@gmail.com

pgpx34Zv0GMRg.pgp
Description: PGP signature


RE: [PHP] isset not functioning

2009-08-03 Thread Yuri Yarlei

Io, try do like this:

 

You should use $_POST for the security, using $_REQUEST some users can pass a 
inject or someting to crash the aplication, and addslashes is for more security

 

$firstName = addslashes($_POST['firstname']);

 

if(isset($firstName) && !empty($firstName)) {
$name = $firstName;
} else {
$name = 'Sir or Madam';
}


Yuri Yarlei.
Programmer PHP, CSS, Java, PostregreSQL;
Today PHP, tomorrow Java, after the world.
Kyou wa PHP, ashita wa Java, sono ato sekai desu.


 
> Date: Mon, 3 Aug 2009 10:08:08 -0700
> From: allenmcc...@gmail.com
> To: parha...@gmail.com
> CC: php-general@lists.php.net
> Subject: [PHP] isset not functioning
> 
> I created a simple survey for my work website, most of the PHP is on my
> process.php document, which is referenced by a form on a seperate page
> containing the form with the method of "post".
> 
> On my process.php page, the script obtains the field data using the
> $_REQUEST[] function.
> 
> I have a small if statement to check to see if they filled out the
> 'firstname' field, and if they did not, to replace $name with "Sir or
> Madam". Unfortunately, $name always equals "Sir or Madam", wether a value
> for "firstname" was entered or not.
> 
> All the of the other instances of using $_REQUEST[] functions just fine, but
> don't make use of if or isset. Here is the code snippet:
> 
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
> $name = $_REQUEST['firstname'];
> } else {
> $name = 'Sir or Madam';
> }
> 
> I also tried adding an underscore to $RESULT (I got the code for this from a
> php.net comment on the manual), to make it $_RESULT, but this doesn't seem
> to be a pre-set function, and it still does not make it work. I am guessing
> the user neglected to define $RESULT in his snippet, or I overlooked it.
> 
> Can anyone see any problems with the code?

_
Novo Internet Explorer 8. Baixe agora, é grátis!
http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmail&utm_medium=Tagline&utm_campaign=IE8

Re: [PHP] isset not functioning

2009-08-03 Thread Steve Brown
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
>  $name = $_REQUEST['firstname'];
>  } else {
>  $name = 'Sir or Madam';
> }
>

> Can anyone see any problems with the code?

Your conditional will never evaluate to true.  What is $RESULT?  Where
did it come from? $RESULT is not a built-in PHP variable or function,
so empty($RESULT) will always be true, making !empty(...) always
false.

Also, it should be noted that if a form field exists, it will exist in
the form data POSTed to PHP, even if the field is empty.

I'm guessing that what you want to do is something like this:

if(!empty($_POST['firstname']) {
$name = $_POST['firstname'];
} else {
$name = 'Sir or Madam';
}

empty() will evaluate to false if the field is empty OR if the field
does not exist.  Also not the use of $_POST instead of $_REQUEST.
This will ensure that your data is actually coming from the form
instead of an attacker trying to inject data with $_GET variables or
some other source.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset not functioning -RESOLVED

2009-08-03 Thread Allen McCabe
Thanks!

On Mon, Aug 3, 2009 at 10:13 AM, Andrew Ballard  wrote:

>  On Mon, Aug 3, 2009 at 1:08 PM, Allen McCabe
> wrote:
> > I created a simple survey for my work website, most of the PHP is on my
> > process.php document, which is referenced by a form on a seperate page
> > containing the form with the method of "post".
> >
> > On my process.php page, the script obtains the field data using the
> > $_REQUEST[] function.
> >
> > I have a small if statement to check to see if they filled out the
> > 'firstname' field, and if they did not, to replace $name with "Sir or
> > Madam". Unfortunately, $name always equals "Sir or Madam", wether a value
> > for "firstname" was entered or not.
> >
> > All the of the other instances of using $_REQUEST[] functions just fine,
> but
> > don't make use of if or isset. Here is the code snippet:
> >
> > if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
> >  $name = $_REQUEST['firstname'];
> >  } else {
> >  $name = 'Sir or Madam';
> > }
> >
> > I also tried adding an underscore to $RESULT (I got the code for this
> from a
> > php.net comment on the manual), to make it $_RESULT, but this doesn't
> seem
> > to be a pre-set function, and it still does not make it work. I am
> guessing
> > the user neglected to define $RESULT in his snippet, or I overlooked it.
> >
> > Can anyone see any problems with the code?
> >
>
> You are switching from $_REQUEST to $RESULT. Trying to use $_RESULT
> won't make it any better.
>
> Andrew
>


Re: [PHP] isset not functioning

2009-08-03 Thread Ollisso
On Mon, 03 Aug 2009 20:11:44 +0300, "Parham Doustdar"   
wrote:



Your if-statement should be like this:

[code]
if(isset($_REQUEST['firstname']) && !empty($_REQUEST['firstname'])) {
...
}
[/code]


Or even:

[code]
if(!empty($_REQUEST['firstname'])) {
 ...
}
[/code]

Because empty will also check if variable exists

--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset not functioning

2009-08-03 Thread Parham Doustdar
Your if-statement should be like this:

[code]
if(isset($_REQUEST['firstname']) && !empty($_REQUEST['firstname'])) {
...
}
[/code]
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Allen McCabe"  wrote in message 
news:657acef20908031008nc2c29cdo3e13733bc6f29...@mail.gmail.com...
>I created a simple survey for my work website, most of the PHP is on my
> process.php document, which is referenced by a form on a seperate page
> containing the form with the method of "post".
>
> On my process.php page, the script obtains the field data using the
> $_REQUEST[] function.
>
> I have a small if statement to check to see if they filled out the
> 'firstname' field, and if they did not, to replace $name with "Sir or
> Madam". Unfortunately, $name always equals "Sir or Madam", wether a value
> for "firstname" was entered or not.
>
> All the of the other instances of using $_REQUEST[] functions just fine, 
> but
> don't make use of if or isset. Here is the code snippet:
>
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
> $name = $_REQUEST['firstname'];
> } else {
> $name = 'Sir or Madam';
> }
>
> I also tried adding an underscore to $RESULT (I got the code for this from 
> a
> php.net comment on the manual), to make it $_RESULT, but this doesn't seem
> to be a pre-set function, and it still does not make it work. I am 
> guessing
> the user neglected to define $RESULT in his snippet, or I overlooked it.
>
> Can anyone see any problems with the code?
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset not functioning

2009-08-03 Thread Andrew Ballard
On Mon, Aug 3, 2009 at 1:08 PM, Allen McCabe wrote:
> I created a simple survey for my work website, most of the PHP is on my
> process.php document, which is referenced by a form on a seperate page
> containing the form with the method of "post".
>
> On my process.php page, the script obtains the field data using the
> $_REQUEST[] function.
>
> I have a small if statement to check to see if they filled out the
> 'firstname' field, and if they did not, to replace $name with "Sir or
> Madam". Unfortunately, $name always equals "Sir or Madam", wether a value
> for "firstname" was entered or not.
>
> All the of the other instances of using $_REQUEST[] functions just fine, but
> don't make use of if or isset. Here is the code snippet:
>
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
>  $name = $_REQUEST['firstname'];
>  } else {
>  $name = 'Sir or Madam';
> }
>
> I also tried adding an underscore to $RESULT (I got the code for this from a
> php.net comment on the manual), to make it $_RESULT, but this doesn't seem
> to be a pre-set function, and it still does not make it work. I am guessing
> the user neglected to define $RESULT in his snippet, or I overlooked it.
>
> Can anyone see any problems with the code?
>

You are switching from $_REQUEST to $RESULT. Trying to use $_RESULT
won't make it any better.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset question

2009-06-22 Thread Ford, Mike
On 19 June 2009 19:53, Ashley Sheridan advised:

> On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
>> On 18 June 2009 20:25, LAMP advised:
>> 
>>> using !empty() instead isset() will work if you don't care for PHP
>>> Notice: Undefined variable... If you want to avoid PHP Notice
>>> you have
>>> to use both:
>>> 
>>> $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
>>> mortgage amount is  $mort\n" : " ";
>> 
>> Absolute rubbish -- as it says at http://php.net/empty, "empty($var)
is
>> the opposite of (boolean)$var, except that no warning is generated
when
>> the variable is not set." -- so "protecting" empty() with an isset()
is
>> a total waste of time, space and cpu cycles.
>> 
>> Cheers!
>> 
>> Mike
>> 
>>  --
>> Mike Ford,  Electronic Information Developer,
>> C507, Leeds Metropolitan University, Civic Quarter Campus,
>> Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
>> Email: m.f...@leedsmet.ac.uk
>> Tel: +44 113 812 4730
>> 
>> 
>> 
>> 
>> 
>> To view the terms under which this email is distributed,
> please go to http://disclaimer.leedsmet.ac.uk/email.htm
>> 
> To be honest, you're still opening yourself up to attack that
> way. What
> I'd do is first assign the variable to a forced int, and then use that
> result if it is >0: 
> 
> $mortgage = (isset($_REQUEST['mort'])?intval($_REQUEST['mort']):0;
> 
> $msg .= ($mortgage > 0)?"The mortgage amount is $mortgage":"";

Too true -- I have a parameter-checking system that does this
automatically for me, so I tend not to think of it when writing actual
processing code. My bad, probably, but good catch.

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730



To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-21 Thread Ashley Sheridan
On Sun, 2009-06-21 at 13:57 -0400, Gary wrote:
> How does echoing back to the page make it vulnerable? This does not go to a 
> DB if that makes any difference.
> 
> Gary
> 
> 
> "Paul M Foster"  wrote in message 
> news:20090621032151.gb14...@quillandmouse.com...
> > On Sat, Jun 20, 2009 at 12:20:56PM +0100, Ashley Sheridan wrote:
> >
> >> On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote:
> >> > On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote:
> >> >
> >> > > On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
> >> > > > On 18 June 2009 20:25, LAMP advised:
> >> > > >
> >> > > > > using !empty() instead isset() will work if you don't care for 
> >> > > > > PHP
> >> > > > > Notice: Undefined variable... If you want to avoid PHP Notice
> >> > > > > you have
> >> > > > > to use both:
> >> > > > >
> >> > > > > $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> >> > > > > mortgage amount is  $mort\n" : " ";
> >> > > >
> >> > > > Absolute rubbish -- as it says at http://php.net/empty, 
> >> > > > "empty($var) is
> >> > > > the opposite of (boolean)$var, except that no warning is generated 
> >> > > > when
> >> > > > the variable is not set." -- so "protecting" empty() with an 
> >> > > > isset() is
> >> > > > a total waste of time, space and cpu cycles.
> >> >
> >> > 
> >> >
> >> > > >
> >> > > To be honest, you're still opening yourself up to attack that way.
> >> >
> >> > Why and how?
> >> >
> >> > Paul
> >> >
> >> > --
> >> > Paul M. Foster
> >> >
> >> I've only done a little reading on this, but you're opening yourself up
> >> to a XSS attack. If someone posted '//malicious code
> >> here' to your PHP script, you'd essentially be printing that
> >> right back out onto your page.
> >
> > I see. You're not talking about being vulnerable because of isset/empty,
> > but by echoing it back to the page. Yes, I agree there. You have to
> > sanitize it first.
> >
> > Paul
> >
> > -- 
> > Paul M. Foster 
> 
> 
> 
My assumption was that because it was displaying the mortgage amount to
the user, that it would at some point store it too.

Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-21 Thread Gary
How does echoing back to the page make it vulnerable? This does not go to a 
DB if that makes any difference.

Gary


"Paul M Foster"  wrote in message 
news:20090621032151.gb14...@quillandmouse.com...
> On Sat, Jun 20, 2009 at 12:20:56PM +0100, Ashley Sheridan wrote:
>
>> On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote:
>> > On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote:
>> >
>> > > On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
>> > > > On 18 June 2009 20:25, LAMP advised:
>> > > >
>> > > > > using !empty() instead isset() will work if you don't care for 
>> > > > > PHP
>> > > > > Notice: Undefined variable... If you want to avoid PHP Notice
>> > > > > you have
>> > > > > to use both:
>> > > > >
>> > > > > $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
>> > > > > mortgage amount is  $mort\n" : " ";
>> > > >
>> > > > Absolute rubbish -- as it says at http://php.net/empty, 
>> > > > "empty($var) is
>> > > > the opposite of (boolean)$var, except that no warning is generated 
>> > > > when
>> > > > the variable is not set." -- so "protecting" empty() with an 
>> > > > isset() is
>> > > > a total waste of time, space and cpu cycles.
>> >
>> > 
>> >
>> > > >
>> > > To be honest, you're still opening yourself up to attack that way.
>> >
>> > Why and how?
>> >
>> > Paul
>> >
>> > --
>> > Paul M. Foster
>> >
>> I've only done a little reading on this, but you're opening yourself up
>> to a XSS attack. If someone posted '//malicious code
>> here' to your PHP script, you'd essentially be printing that
>> right back out onto your page.
>
> I see. You're not talking about being vulnerable because of isset/empty,
> but by echoing it back to the page. Yes, I agree there. You have to
> sanitize it first.
>
> Paul
>
> -- 
> Paul M. Foster 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-20 Thread Paul M Foster
On Sat, Jun 20, 2009 at 12:20:56PM +0100, Ashley Sheridan wrote:

> On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote:
> > On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote:
> >
> > > On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
> > > > On 18 June 2009 20:25, LAMP advised:
> > > >
> > > > > using !empty() instead isset() will work if you don't care for PHP
> > > > > Notice: Undefined variable... If you want to avoid PHP Notice
> > > > > you have
> > > > > to use both:
> > > > >
> > > > > $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> > > > > mortgage amount is  $mort\n" : " ";
> > > >
> > > > Absolute rubbish -- as it says at http://php.net/empty, "empty($var) is
> > > > the opposite of (boolean)$var, except that no warning is generated when
> > > > the variable is not set." -- so "protecting" empty() with an isset() is
> > > > a total waste of time, space and cpu cycles.
> >
> > 
> >
> > > >
> > > To be honest, you're still opening yourself up to attack that way.
> >
> > Why and how?
> >
> > Paul
> >
> > --
> > Paul M. Foster
> >
> I've only done a little reading on this, but you're opening yourself up
> to a XSS attack. If someone posted '//malicious code
> here' to your PHP script, you'd essentially be printing that
> right back out onto your page.

I see. You're not talking about being vulnerable because of isset/empty,
but by echoing it back to the page. Yes, I agree there. You have to
sanitize it first.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-20 Thread Gary
Yes... I echo the code onto the page as well as sending out the message. 
The echo is sort of a "thank you" page, this is what you submitted.  A 
message, which is not going into a DB, is also emailed to the submitter and 
cleint.

Gary
"Waynn Lue"  wrote in message 
news:d29bea5e0906181231r165c5844wecd7d34026621...@mail.gmail.com...
>I notice that you're checking $_POST['mort'] but you're echoing $mort,
> is that your actual code?
>
> On 6/18/09, Gary  wrote:
>> I have a form that gives the submitter a choice or either one set of
>> questions, or another. I am still getting the message even if the input 
>> was
>> left blank.  So on the line below,
>>
>> $msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";
>>
>> I get
>>
>> The mortgage amount is
>>
>> What am I missing here?
>>
>> Thanks
>>
>> Gary
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-20 Thread Reese

Waynn Lue wrote:

I notice that you're checking $_POST['mort'] but you're echoing $mort,
is that your actual code?


That was my observation as well. Is $mort = $POST['mort']; being
set somewhere else or not? If not, how is your script supposed to
know what value $mort should be?

And, what the other guys said. Gary, before you do anything with
submitted data you need to process it against strip_tags() and/or
htmlentities() at the very least, mysql_real_escape_string() if
the data goes to a db.

Reese

--



On 6/18/09, Gary  wrote:

I have a form that gives the submitter a choice or either one set of
questions, or another. I am still getting the message even if the input was
left blank.  So on the line below,

$msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-20 Thread Ashley Sheridan
On Sat, 2009-06-20 at 00:19 -0400, Paul M Foster wrote:
> On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote:
> 
> > On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
> > > On 18 June 2009 20:25, LAMP advised:
> > >
> > > > using !empty() instead isset() will work if you don't care for PHP
> > > > Notice: Undefined variable... If you want to avoid PHP Notice
> > > > you have
> > > > to use both:
> > > >
> > > > $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> > > > mortgage amount is  $mort\n" : " ";
> > >
> > > Absolute rubbish -- as it says at http://php.net/empty, "empty($var) is
> > > the opposite of (boolean)$var, except that no warning is generated when
> > > the variable is not set." -- so "protecting" empty() with an isset() is
> > > a total waste of time, space and cpu cycles.
> 
> 
> 
> > >
> > To be honest, you're still opening yourself up to attack that way. 
> 
> Why and how?
> 
> Paul
> 
> -- 
> Paul M. Foster
> 
I've only done a little reading on this, but you're opening yourself up
to a XSS attack. If someone posted '//malicious code
here' to your PHP script, you'd essentially be printing that
right back out onto your page.

Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-19 Thread Paul M Foster
On Fri, Jun 19, 2009 at 07:52:40PM +0100, Ashley Sheridan wrote:

> On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
> > On 18 June 2009 20:25, LAMP advised:
> >
> > > using !empty() instead isset() will work if you don't care for PHP
> > > Notice: Undefined variable... If you want to avoid PHP Notice
> > > you have
> > > to use both:
> > >
> > > $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> > > mortgage amount is  $mort\n" : " ";
> >
> > Absolute rubbish -- as it says at http://php.net/empty, "empty($var) is
> > the opposite of (boolean)$var, except that no warning is generated when
> > the variable is not set." -- so "protecting" empty() with an isset() is
> > a total waste of time, space and cpu cycles.



> >
> To be honest, you're still opening yourself up to attack that way. 

Why and how?

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset question

2009-06-19 Thread Ashley Sheridan
On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
> On 18 June 2009 20:25, LAMP advised:
> 
> > using !empty() instead isset() will work if you don't care for PHP
> > Notice: Undefined variable... If you want to avoid PHP Notice
> > you have
> > to use both:
> > 
> > $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> > mortgage amount is  $mort\n" : " ";
> 
> Absolute rubbish -- as it says at http://php.net/empty, "empty($var) is
> the opposite of (boolean)$var, except that no warning is generated when
> the variable is not set." -- so "protecting" empty() with an isset() is
> a total waste of time, space and cpu cycles.
> 
> Cheers!
> 
> Mike
> 
>  --
> Mike Ford,  Electronic Information Developer,
> C507, Leeds Metropolitan University, Civic Quarter Campus, 
> Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
> Email: m.f...@leedsmet.ac.uk
> Tel: +44 113 812 4730
> 
> 
> 
> 
> 
> To view the terms under which this email is distributed, please go to 
> http://disclaimer.leedsmet.ac.uk/email.htm
> 
To be honest, you're still opening yourself up to attack that way. What
I'd do is first assign the variable to a forced int, and then use that
result if it is >0:

$mortgage = (isset($_REQUEST['mort'])?intval($_REQUEST['mort']):0;

$msg .= ($mortgage > 0)?"The mortgage amount is $mortgage":"";

Thanks
Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset question

2009-06-19 Thread Ford, Mike
On 18 June 2009 20:25, LAMP advised:

> using !empty() instead isset() will work if you don't care for PHP
> Notice: Undefined variable... If you want to avoid PHP Notice
> you have
> to use both:
> 
> $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> mortgage amount is  $mort\n" : " ";

Absolute rubbish -- as it says at http://php.net/empty, "empty($var) is
the opposite of (boolean)$var, except that no warning is generated when
the variable is not set." -- so "protecting" empty() with an isset() is
a total waste of time, space and cpu cycles.

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset question

2009-06-18 Thread Yuri Yarlei

The isset or empty, it's return a boolean (true 1, false 0), the isset will 
return true if the variable will have been initiated, the empty will return 
true if the variable is empty, but for that the variable need to be initiated. 
You can do it in a many ways, like:


$msg.= (isset($_POST['mort']) && !empty($_POST['mort']) ? "The mortgage amount 
is  $mort\n" : " ");

or

$msg.= ($_POST['mort'] == '' ? "The mortgage amount is  $mort\n" : " ");

or

$msg.= (strlen($_POST['mort']) > 0 ? "The mortgage amount is  $mort\n" : " ");



Yuri Yarlei.
Programmer PHP, CSS, Java, PostregreSQL;
Today PHP, tomorrow Java, after the world.
Kyou wa PHP, ashita wa Java, sono ato sekai desu.



> Date: Thu, 18 Jun 2009 20:07:09 +0100
> From: stut...@gmail.com
> To: gwp...@ptd.net
> CC: php-general@lists.php.net
> Subject: Re: [PHP] isset question
> 
> 2009/6/18 Gary :
> > I have a form that gives the submitter a choice or either one set of
> > questions, or another. I am still getting the message even if the input was
> > left blank.  So on the line below,
> >
> > $msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";
> >
> > I get
> >
> > The mortgage amount is
> >
> > What am I missing here?
> 
> A variable "isset" even if it's empty. Either compare it to an empty
> string or test the result from strlen against 0.
> 
> -Stuart
> 
> -- 
> http://stut.net/
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_
Conheça os novos produtos Windows Live! Clique aqui.
http://www.windowslive.com.br

Re: [PHP] isset question

2009-06-18 Thread Waynn Lue
I notice that you're checking $_POST['mort'] but you're echoing $mort,
is that your actual code?

On 6/18/09, Gary  wrote:
> I have a form that gives the submitter a choice or either one set of
> questions, or another. I am still getting the message even if the input was
> left blank.  So on the line below,
>
> $msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";
>
> I get
>
> The mortgage amount is
>
> What am I missing here?
>
> Thanks
>
> Gary
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-18 Thread LAMP

Steve wrote:
Use !empty($_POST['mort']) instead of isset() for form input since the 
form will still set an empty value if left blank.


Gary wrote:
I have a form that gives the submitter a choice or either one set of 
questions, or another. I am still getting the message even if the 
input was left blank.  So on the line below,


$msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";

I get

The mortgage amount is

What am I missing here?

Thanks

Gary


  




No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.339 / Virus Database: 
270.12.78/2185 - Release Date: 06/18/09 05:53:00


  


using !empty() instead isset() will work if you don't care for PHP 
Notice: Undefined variable... If you want to avoid PHP Notice you have 
to use both:


$msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The 
mortgage amount is  $mort\n" : " ";



afan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-18 Thread Steve
Use !empty($_POST['mort']) instead of isset() for form input since the 
form will still set an empty value if left blank.


Gary wrote:
I have a form that gives the submitter a choice or either one set of 
questions, or another. I am still getting the message even if the input was 
left blank.  So on the line below,


$msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";

I get

The mortgage amount is

What am I missing here?

Thanks

Gary 




  




No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.339 / Virus Database: 270.12.78/2185 - Release Date: 06/18/09 05:53:00


  


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset question

2009-06-18 Thread Stuart
2009/6/18 Gary :
> I have a form that gives the submitter a choice or either one set of
> questions, or another. I am still getting the message even if the input was
> left blank.  So on the line below,
>
> $msg.=  isset($_POST['mort']) ? "The mortgage amount is  $mort\n" : " ";
>
> I get
>
> The mortgage amount is
>
> What am I missing here?

A variable "isset" even if it's empty. Either compare it to an empty
string or test the result from strlen against 0.

-Stuart

-- 
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset($a->b) even if $a->b = null

2007-08-17 Thread Michael Preslar
On 8/17/07, Olav Mørkrid <[EMAIL PROTECTED]> wrote:
> how do i test if a property of a stdclass object is set, even if its
> value is null, similar to how array_key_exists() works for arrays.
>
> the following method fails:
>
>   $a->b = null;
>   if(isset($a->b))
> echo "yes";
>
> and property_exists() seems only to work for defined objects.
>
> hope someone can help. thanks!

Seems your asking for something similar to perl's exists() function..
Best I can come up with is...

$a->b = null;

if (is_null($a->b) || isset($a->b)) {
print "yes";
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset($a->b) even if $a->b = null

2007-08-17 Thread Borokov Smith

Olav Mørkrid schreef:

how do i test if a property of a stdclass object is set, even if its
value is null, similar to how array_key_exists() works for arrays.

the following method fails:

  $a->b = null;
  if(isset($a->b))
echo "yes";

and property_exists() seems only to work for defined objects.

hope someone can help. thanks!

  

if (isset($a -> b) && $a -> b != null) { echo "yes"; }

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Isset Errors

2007-05-09 Thread Richard Lynch


On Wed, May 9, 2007 9:17 am, Davide Bernard wrote:
> Anyone got any suggestions on getting rid of these errors below?
>
>
> [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP
> Notice:  Undefined index:  userstate in /srv/www/htdocs/resetpw.php on
> line 31, referer: https://ams.unt.edu/resetpw.php
> [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP
> Notice:  Undefined index:  userstate in /srv/www/htdocs/resetpw.php on
> line 36, referer: https://ams.unt.edu/resetpw.php
>
>
> Here's the lines of code I am getting the errors in PHP 5...Where can
> I insert some code to define 'userstate' ?
>
>
> 24. if (identifyUser()) {
> 25.   if ((isset($_SESSION['clientinfo']['ssn'][0]) &&
> strcmp('9', $_SESSION['clientinfo']['ssn'][0]))
> 26.   || isset($_SESSION['clientsinfo'])) {
> 27.   $_SESSION['userstate'] = 'confirmssn';
> 28.  } else {
> 29.   $_SESSION['userstate'] = 'ssnverified';
> 30.  }
> 31. } elseif ($_SESSION['userstate'] == 'confirmssn' && confirmSSN())
> {

elseif (isset($_SESSION['userstate']) && $_SESSION['userstate'] ==
'confirmssn' && confirmSSN()){

> 32.  $_SESSION['userstate'] = 'ssnverified';
> 33. }
> 34. initMenu();
> 35. if (isset($_SESSION['userstate'])) return 0;
> 36. if ($_SESSION['userstate'] == 'confirmssn') {
> 37.   themeHeader();
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Isset Errors

2007-05-09 Thread Edward Kay


> -Original Message-
> From: Davide Bernard [mailto:[EMAIL PROTECTED]
> Sent: 09 May 2007 15:18
> To: php-general@lists.php.net
> Subject: [PHP] Isset Errors
> 
> 
> Anyone got any suggestions on getting rid of these errors below?
> 
> 
> [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP 
> Notice:  Undefined index:  userstate in 
> /srv/www/htdocs/resetpw.php on line 31, referer: 
> https://ams.unt.edu/resetpw.php 
> [Wed May 09 08:59:05 2007] [error] [client 192.168.225.246] PHP 
> Notice:  Undefined index:  userstate in 
> /srv/www/htdocs/resetpw.php on line 36, referer: 
> https://ams.unt.edu/resetpw.php 
> 
>  
> Here's the lines of code I am getting the errors in PHP 5...Where 
> can I insert some code to define 'userstate' ?
> 
> 
> 24. if (identifyUser()) {
> 25.   if ((isset($_SESSION['clientinfo']['ssn'][0]) && 
> strcmp('9', $_SESSION['clientinfo']['ssn'][0]))
> 26.   || isset($_SESSION['clientsinfo'])) {
> 27.   $_SESSION['userstate'] = 'confirmssn';
> 28.  } else {
> 29.   $_SESSION['userstate'] = 'ssnverified';
> 30.  }
> 31. } elseif ($_SESSION['userstate'] == 'confirmssn' && confirmSSN()) {
> 32.  $_SESSION['userstate'] = 'ssnverified';
> 33. }
> 34. initMenu();
> 35. if (isset($_SESSION['userstate'])) return 0;
> 36. if ($_SESSION['userstate'] == 'confirmssn') {
> 37.   themeHeader();
> 

If identifyUser() returns false, $_SESSION['userstate'] is not defined.

Edward

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-18 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-04-17 13:59:39 +0200:
> 
> > > The count is maintained internally as items are 
> > added/removed, and it 
> > > is an O(1) operation for PHP to "count" the array, as it 
> > already knows 
> > > the answer and just returns it.
> 
> 
> Hi nothing to do with the actual topic, i am just wondering how you get this
> "internals" information you all seem to know so much about

that's the whatsinside compulsive/obsessive personality disorder.

> it is very interesting and i'd like to add it to some of my "late
> night" reading if possible :)

get ready for an allnighter, http://marc.info/ awaits you.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-17 Thread Richard Lynch
On Mon, April 16, 2007 8:06 pm, Robert Cummings wrote:
> On Mon, 2007-04-16 at 19:05 -0500, Richard Lynch wrote:
>> On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote:
>> > if I know it's an array I'll definitely use empty() over count()
>> 
>> > count() needs to actually count the items where as empty() can
>> return
>> > false
>> > as soon as it finds a singel element ... maybe I'm mistaken - if
>> so
>> > please
>> > put me right.
>>
>> You're wrong.
>>
>> The count is maintained internally as items are added/removed, and
>> it
>> is an O(1) operation for PHP to "count" the array, as it already
>> knows
>> the answer and just returns it.
>
> Fastest way to check if an array has elements...
>
> 
> if( $array )
> {
> }
>
> ?>

IIRC, in olden days of PHP 3.x, if the first element was '0' or 0,
then this test would result in FALSE...

Which is not to say it's "bad" now, but to explain why an old hand
might be leery of using it.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset

2007-04-17 Thread Richard Lynch
On Tue, April 17, 2007 6:59 am, Tim wrote:
> 
>> > The count is maintained internally as items are
>> added/removed, and it
>> > is an O(1) operation for PHP to "count" the array, as it
>> already knows
>> > the answer and just returns it.
> 
>
> Hi nothing to do with the actual topic, i am just wondering how you
> get this
> "internals" information you all seem to know so much about, it is very
> interesting and i'd like to add it to some of my "late night" reading
> if
> possible :)

Invent a time machine, go back to the future, and subscribe to this
list in 1997...

Oh.

Well, another option is to just read a heck of a lot of the archives,
and the manual, and maybe the "Internals" list (not for the faint of
heart) and the books, and maybe peruse some PHP source once in awhile
and...

There are many paths to enlightenment.

Mostly all of them are long and torturous paths.

:-)

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-17 Thread Robert Cummings
On Tue, 2007-04-17 at 13:14 +0100, Stut wrote:
> Tim wrote:
> > 
> >>> The count is maintained internally as items are 
> >> added/removed, and it 
> >>> is an O(1) operation for PHP to "count" the array, as it 
> >> already knows 
> >>> the answer and just returns it.
> > 
> > 
> > Hi nothing to do with the actual topic, i am just wondering how you get this
> > "internals" information you all seem to know so much about, it is very
> > interesting and i'd like to add it to some of my "late night" reading if
> > possible :)
> 
> Just guessing, but I'd say probably the source code. That's where most 
> of the internals of PHP are documented. ;)

Several sources... the C source code as Stut has presumed :) Also from
reading the PHP-DEV list where the source is often discussed.
Additionally, some of it is from my early Computer Science background
where there's a large focus on data structures and algorithms.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-17 Thread Stut

Tim wrote:


The count is maintained internally as items are 
added/removed, and it 
is an O(1) operation for PHP to "count" the array, as it 
already knows 

the answer and just returns it.



Hi nothing to do with the actual topic, i am just wondering how you get this
"internals" information you all seem to know so much about, it is very
interesting and i'd like to add it to some of my "late night" reading if
possible :)


Just guessing, but I'd say probably the source code. That's where most 
of the internals of PHP are documented. ;)


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset

2007-04-17 Thread Tim
 


> > The count is maintained internally as items are 
> added/removed, and it 
> > is an O(1) operation for PHP to "count" the array, as it 
> already knows 
> > the answer and just returns it.


Hi nothing to do with the actual topic, i am just wondering how you get this
"internals" information you all seem to know so much about, it is very
interesting and i'd like to add it to some of my "late night" reading if
possible :)

Regards,

Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Robert Cummings
On Mon, 2007-04-16 at 19:05 -0500, Richard Lynch wrote:
> On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote:
> > if I know it's an array I'll definitely use empty() over count() 
> > count() needs to actually count the items where as empty() can return
> > false
> > as soon as it finds a singel element ... maybe I'm mistaken - if so
> > please
> > put me right.
> 
> You're wrong.
> 
> The count is maintained internally as items are added/removed, and it
> is an O(1) operation for PHP to "count" the array, as it already knows
> the answer and just returns it.

Fastest way to check if an array has elements...



Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Richard Lynch
On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote:
> if I know it's an array I'll definitely use empty() over count() 
> count() needs to actually count the items where as empty() can return
> false
> as soon as it finds a singel element ... maybe I'm mistaken - if so
> please
> put me right.

You're wrong.

The count is maintained internally as items are added/removed, and it
is an O(1) operation for PHP to "count" the array, as it already knows
the answer and just returns it.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Al

I've been using empty() for about 5 years, obeying the rules for empty() in the 
php manual
"Appendix P. PHP type comparison tables" and have never seen it generate any 
type of error message.

If you guys know of at least one exception, please clue us in on it.


Jim Lucas wrote:

Stut wrote:

tedd wrote:

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because 
$_REQUEST['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


I've been accuse of that too, but what's your solution?


In the above example,

  if (isset($_GET['something']) && !empty($_GET['something'])) {

is the same as...

  if (!empty($_GET['something'])) {

So, in that particular line of code the isset is a pointless waste of 
cycles.


-Stut

these two lines are not the same infact, with the first, you will not 
get a E_NOTICE warning, but with the second you will.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Jochem Maas
Richard Lynch wrote:
> On Mon, April 16, 2007 5:35 pm, Tim Earl wrote:
>> What about in the following context?
>>
>> $arr = array();
>> If (!empty($arr)) { }
>>
>> This is where i have found it to be the most usefull...
> 
> If I'm already certain that it's an array, I just use 'count' personally.
> 
> 'empty' takes a mixed data type, and could return TRUE for, say, 'foo'
> even though you are expecting an array there.
> 
> I think it's a better practice to use the "right" weapon and use
> count() on an array to see if it's empty or not.

php -r 'var_dump(count("foo"));'

outputs:
int(1)

so my strategy is usually

if (!empty($r) && is_array($r)) {
// good to go.
}

if I know it's an array I'll definitely use empty() over count() 
count() needs to actually count the items where as empty() can return false
as soon as it finds a singel element ... maybe I'm mistaken - if so please
put me right.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Richard Lynch
On Mon, April 16, 2007 11:18 am, Jim Lucas wrote:
> these two lines are not the same infact, with the first, you will not
> get a E_NOTICE warning, but
> with the second you will.

I dunno what you are thinking of, but the manual says:

"empty() is the opposite of (boolean) var, except that no warning is
generated when the variable is not set."

I am reasonably certain that "empty", like "isset" is not, in fact, a
function, but is a language construct (like "if" and "foreach") and it
does not attempt to use the variable per se, so does not generate an
E_NOTICE.

I am also reasonably certain that this has been true since "empty"
debuted in the language, but won't swear to that in court.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset

2007-04-16 Thread Richard Lynch
On Mon, April 16, 2007 5:35 pm, Tim Earl wrote:
> What about in the following context?
>
> $arr = array();
> If (!empty($arr)) { }
>
> This is where i have found it to be the most usefull...

If I'm already certain that it's an array, I just use 'count' personally.

'empty' takes a mixed data type, and could return TRUE for, say, 'foo'
even though you are expecting an array there.

I think it's a better practice to use the "right" weapon and use
count() on an array to see if it's empty or not.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Richard Lynch
On Mon, April 16, 2007 11:12 am, tedd wrote:
> I've been accuse of that too, but what's your solution?

*MY* solution:

Don't use empty because its behaviour changed wrt "0" in various
versions, so it's just gonna bite you in the butt like it did me. :-)

I generally do this basic algorithm:

#1
Use isset() to see what came "in" as inputs, to decide basic business
logic for large-scale chunks of code
Also use specific values with == for simple if/else or switch setup here

#2
Within an isset() (and possible == 'foo' block)
Check the validity of the data *WAY* more than just "empty"
  preg_match with a white-list pattern is good
  ctype for specific data is good
  checking with strlen() (possibly with trim() first) is good
  typecasting any data that should be of a certain type is good
  checking inputs against a static list of valid inputs is good

#3
Still within the block,
Prep input data for output formats as needed for this section:
  $foo_sql = mysql_real_escape_string($foo, $connection);
  $foo_html = htmlentities($foo);
  $foo_json = json_encode(foo);

Only after all that is done do I start actually doing fine-tuned
business logic of the body of my code.

I may end up repeating the same large structure I had above, to decide
what code to run, or maybe it will be a different structure, depending
on what the script does.

But all my data is clean and prepped at this point, so I can just use it.

Within that code, if I'm writing an SQL query, I can just do:

$query = "whatever SQL blah blah '$foo_sql' blah ";

If I'm going to echo out $foo, I can just do:
echo "whatever blah blah $foo_html blah ";

I just tossed in JSON even though I've never used it in my life so
far, but I presume it would be like:

?>


http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset

2007-04-16 Thread Tim Earl
 

> -Message d'origine-
> De : Robert Cummings [mailto:[EMAIL PROTECTED] 
> Envoyé : lundi 16 avril 2007 20:28
> À : Edward Vermillion
> Cc : php Lists
> Objet : Re: [PHP] isset
> 
> On Mon, 2007-04-16 at 13:16 -0500, Edward Vermillion wrote:
> > On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote:
> > 
> > [snip]
> > 
> > >
> > >
> > > Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't 
> > > generate notices.
> > >
> 
> Strings only containing only spaces are not empty. Strings 
> containing a 0 are empty. It's crap for almost any kind of 
> validation routine. It's one of those useless, magical, shoot 
> newbies in the toes functions. But then I guess to each their own :)

What about in the following context?

$arr = array();
If (!empty($arr)) { }

This is where i have found it to be the most usefull...


tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Richard Lynch
On Sun, April 15, 2007 12:07 pm, [EMAIL PROTECTED] wrote:
> I have E_NOTICE turned off. :)

Your first mistake.

:-)

E_NOTICE on is a royal pain at first, but will catch bugs for you, and
save you development time in the long run.

Turn it on for your next new project and try it.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Richard Lynch
On Sat, April 14, 2007 8:36 pm, Richard Kurth wrote:
> What do you do when isset does not work? If I send data in a
> $_REQUEST['var'] like
> if (isset($_REQUEST['var'])) {
> }
> Put var has no data it still says it is set. Because $_REQUEST['var']
> = ""
> and isset thinks "" is set

It *is* set.

It just happens to be the empty string.

That is VERY different from not being set at all.

If you do not want to allow the empty string as a valid input, that
should, imho, be handled by your data validation routines, which
happen after your business logic of doing whatever based on isset()

http://php.net/strlen is a good one for that.

In other words, use isset() to decide what the user is trying to do
first.

Then use data validation to decide if they have provided
valid/suitable input.  If the input is egregious enough (i.e., no
normal human would ever generate that state) you can respond
differently with, say, die("hacker");

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Stut

Robert Cummings wrote:

On Mon, 2007-04-16 at 09:27 -0700, Jim Lucas wrote:

Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST['var'] 
= ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}

The isset is a pointless waste of cycles.

-Stut


well, as the OP said, he wants to know when the variable has a value other the 
"".

So, to check for that you have to do something like this right?

if ( $var != '' ) {}
if ( strlen($var) > 0 ) {}
if ( !empty($var) ) {}
... a number of other ideas come to mind, but

none of them will work, because they will always product a E_NOTICE warning.

You COULD always use empty() prefixed with an @ to quiet the E_NOTICE,


Stut wouldn't do that... especially not after calling isset() a waste of
cycles. using the @ to suppress warnings/errors still invokes the error
system, and that includes any error handler you've custom hooked.

Maybe Stut just writes bad code ;) ;)


I'm thinking I just know some parts of the language better than you lot. 
You guys really should try reading the manual before responding instead 
of just assuming it's the way you think it is.


As far as my coding style goes, that's between me and my $DEITY, but let 
it be noted that even my production servers run with error_reporting as 
E_ALL (but logged to files and not displayed obviously). Knowing how 
isset and empty work is essential to enabling my style of coding PHP, 
which I've found works very well for me.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Edward Vermillion


On Apr 16, 2007, at 1:28 PM, Robert Cummings wrote:


On Mon, 2007-04-16 at 13:16 -0500, Edward Vermillion wrote:

On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote:

[snip]




Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't
generate notices.



Strings only containing only spaces are not empty. Strings  
containing a

0 are empty. It's crap for almost any kind of validation routine. It's
one of those useless, magical, shoot newbies in the toes functions.  
But

then I guess to each their own :)



Strings containing spaces and 0's (and null), while technically not  
empty, may or may not have any meaning in your code outside of being  
empty or at least not interesting. That's why I qualified it with  
whether they have meaning in the code.


I'll agree that it can cause problems if you're not paying attention,  
I've been bitten myself in the past by it. And those things can be  
hard to track down too. :P


Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Robert Cummings
On Mon, 2007-04-16 at 13:16 -0500, Edward Vermillion wrote:
> On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote:
> 
> [snip]
> 
> >
> >
> > Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't
> > generate notices.
> >

Strings only containing only spaces are not empty. Strings containing a
0 are empty. It's crap for almost any kind of validation routine. It's
one of those useless, magical, shoot newbies in the toes functions. But
then I guess to each their own :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Edward Vermillion


On Apr 16, 2007, at 12:30 PM, Robert Cummings wrote:

[snip]




Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't
generate notices.



Lemme guess... You don't like empty() because it thinks null/0/'' is  
empty? Or is there some other reason?


Agreed, it can be tricky if you just use it everywhere, but for most  
things, especially replacing a


if (isset($foo) && $foo != 0/null/''/array()) {}

with

if (!empty($foo))

makes my life a little easier. Especially checking for empty arrays  
since foreach on an empty array will throw a notice or warning, I  
forget which atm.


Of course if null/0/'' are considered valid values in your code then  
you're pretty much stuck with isset() and checking for the value.


And doesn't it also consider 'null' (the string) as empty? Seems like  
I've read folks complaining that returns from a database that are set  
to null get missed also... but since I don't have any code that  
considers null a useful value it's never been a problem for me.


Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Robert Cummings
On Mon, 2007-04-16 at 18:16 +0100, Stut wrote:
> Jim Lucas wrote:
> > Stut wrote:
> >> tedd wrote:
> >>> At 4:08 PM +0100 4/16/07, Stut wrote:
>  Jim Lucas wrote:
> > Richard Kurth wrote:
> >> What do you do when isset does not work? If I send data in a
> >> $_REQUEST['var'] like if (isset($_REQUEST['var'])) {
> >> }
> >> Put var has no data it still says it is set. Because 
> >> $_REQUEST['var'] = ""
> >> and isset thinks "" is set
> >>
> > I use this combination a lot:
> >
> > if ( isset($_GET['something']) && !empty($_GET['something']) ) {
> > // do something here with $_GET['something']
> > }
> 
>  The isset is a pointless waste of cycles.
> 
>  -Stut
> >>>
> >>> I've been accuse of that too, but what's your solution?
> >>
> >> In the above example,
> >>
> >>   if (isset($_GET['something']) && !empty($_GET['something'])) {
> >>
> >> is the same as...
> >>
> >>   if (!empty($_GET['something'])) {
> >>
> >> So, in that particular line of code the isset is a pointless waste of 
> >> cycles.
> >>
> >> -Stut
> >>
> > these two lines are not the same infact, with the first, you will not 
> > get a E_NOTICE warning, but with the second you will.
> 
> No you won't. The empty function does not raise a notice if its argument 
> does not exist.
> 
>  From http://php.net/empty...
> 
> "empty() is the opposite of (boolean) var, except that no warning is 
> generated when the variable is not set."

Bleh, my mistake... I'm so adverse to empty() I forgot it doesn't
generate notices.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Jim Lucas

Stut wrote:

Jim Lucas wrote:

Stut wrote:

tedd wrote:

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because 
$_REQUEST['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


I've been accuse of that too, but what's your solution?


In the above example,

  if (isset($_GET['something']) && !empty($_GET['something'])) {

is the same as...

  if (!empty($_GET['something'])) {

So, in that particular line of code the isset is a pointless waste of 
cycles.


-Stut

these two lines are not the same infact, with the first, you will not 
get a E_NOTICE warning, but with the second you will.


No you won't. The empty function does not raise a notice if its argument 
does not exist.


 From http://php.net/empty...

"empty() is the opposite of (boolean) var, except that no warning is 
generated when the variable is not set."


-Stut


Interesting, have not looked at the empty() man page in a long time.

It use to through E_NOTICE warnings, as far back as I can remember back in 
1999, and 2000

I wonder if they changed it, or the person that told me to do it that way was 
mistaken.

my mistake.

But, as you can tell, others were under the same impression as I.

--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Stut

Jim Lucas wrote:

Stut wrote:

tedd wrote:

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because 
$_REQUEST['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


I've been accuse of that too, but what's your solution?


In the above example,

  if (isset($_GET['something']) && !empty($_GET['something'])) {

is the same as...

  if (!empty($_GET['something'])) {

So, in that particular line of code the isset is a pointless waste of 
cycles.


-Stut

these two lines are not the same infact, with the first, you will not 
get a E_NOTICE warning, but with the second you will.


No you won't. The empty function does not raise a notice if its argument 
does not exist.


From http://php.net/empty...

"empty() is the opposite of (boolean) var, except that no warning is 
generated when the variable is not set."


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Robert Cummings
On Mon, 2007-04-16 at 09:27 -0700, Jim Lucas wrote:
> Stut wrote:
> > Jim Lucas wrote:
> >> Richard Kurth wrote:
> >>> What do you do when isset does not work? If I send data in a
> >>> $_REQUEST['var'] like if (isset($_REQUEST['var'])) {
> >>> }
> >>> Put var has no data it still says it is set. Because $_REQUEST['var'] 
> >>> = ""
> >>> and isset thinks "" is set
> >>>
> >> I use this combination a lot:
> >>
> >> if ( isset($_GET['something']) && !empty($_GET['something']) ) {
> >> // do something here with $_GET['something']
> >> }
> > 
> > The isset is a pointless waste of cycles.
> > 
> > -Stut
> > 
> well, as the OP said, he wants to know when the variable has a value other 
> the "".
> 
> So, to check for that you have to do something like this right?
> 
>   if ( $var != '' ) {}
>   if ( strlen($var) > 0 ) {}
>   if ( !empty($var) ) {}
>   ... a number of other ideas come to mind, but
> 
> none of them will work, because they will always product a E_NOTICE warning.
> 
> You COULD always use empty() prefixed with an @ to quiet the E_NOTICE,

Stut wouldn't do that... especially not after calling isset() a waste of
cycles. using the @ to suppress warnings/errors still invokes the error
system, and that includes any error handler you've custom hooked.

Maybe Stut just writes bad code ;) ;)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Edward Vermillion


On Apr 16, 2007, at 11:27 AM, Jim Lucas wrote:


Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST 
['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}

The isset is a pointless waste of cycles.
-Stut
well, as the OP said, he wants to know when the variable has a  
value other the "".


So, to check for that you have to do something like this right?

if ( $var != '' ) {}
if ( strlen($var) > 0 ) {}
if ( !empty($var) ) {}
... a number of other ideas come to mind, but

none of them will work, because they will always product a E_NOTICE  
warning.




empty() does NOT produce an E_NOTICE if the variable is not set.  
That's one of the things it considers as empty.


And why I always do !empty($foo) then check for a value such as (! 
empty($foo) && $foo == $bar)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Jim Lucas

Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST['var'] 
= ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


well, as the OP said, he wants to know when the variable has a value other the 
"".

So, to check for that you have to do something like this right?

if ( $var != '' ) {}
if ( strlen($var) > 0 ) {}
if ( !empty($var) ) {}
... a number of other ideas come to mind, but

none of them will work, because they will always product a E_NOTICE warning.

You COULD always use empty() prefixed with an @ to quiet the E_NOTICE,

but, me, I could/would possibly miss that when scanning the code.

I would however see the isset() && !empty() bit of code.

And the amount of time that you save by not using isset(), well, lets just say that if it affected 
the time of your apps performance, I think you have other things to worry about first.



Just for example.  The current project that just took over has about 60,000 lines of code.  Doing a 
quick grep -ri 'isset' * on the dir returns about 475 instances of that function call.  Many of 
which I have added to the system to get rid of E_NOTICE warnings, for the simple fact that I wanted 
to set error reporting to E_ALL.  Bad mistake, over half the scripts fire off warnings left and 
right, because all he was doing for checking was !empty() if ( $var ) {} or if ( $var != '' ) {} 
calls all over the place.


There are two ways that I have found to get rid of the notices.


Example #1

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}

Example #2

if ( @!empty($_GET['something']) ) {
// do something here with $_GET['something']
}

Other suggestions would be gladly accepted.


--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Afan Pasalic

that was actually my point.
:)

-afan


Stut wrote:

tedd wrote:

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because 
$_REQUEST['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


I've been accuse of that too, but what's your solution?


In the above example,

  if (isset($_GET['something']) && !empty($_GET['something'])) {

is the same as...

  if (!empty($_GET['something'])) {

So, in that particular line of code the isset is a pointless waste of 
cycles.


-Stut



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Jim Lucas

Stut wrote:

tedd wrote:

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because 
$_REQUEST['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


I've been accuse of that too, but what's your solution?


In the above example,

  if (isset($_GET['something']) && !empty($_GET['something'])) {

is the same as...

  if (!empty($_GET['something'])) {

So, in that particular line of code the isset is a pointless waste of 
cycles.


-Stut

these two lines are not the same infact, with the first, you will not get a E_NOTICE warning, but 
with the second you will.


--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Stut

tedd wrote:

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because 
$_REQUEST['var'] = ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut


I've been accuse of that too, but what's your solution?


In the above example,

  if (isset($_GET['something']) && !empty($_GET['something'])) {

is the same as...

  if (!empty($_GET['something'])) {

So, in that particular line of code the isset is a pointless waste of 
cycles.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread tedd

At 4:08 PM +0100 4/16/07, Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST['var'] = ""
and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut



I've been accuse of that too, but what's your solution?

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Jim Lucas

Robert Cummings wrote:

On Mon, 2007-04-16 at 09:27 -0700, Jim Lucas wrote:

Stut wrote:

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST['var'] 
= ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}

The isset is a pointless waste of cycles.

-Stut


well, as the OP said, he wants to know when the variable has a value other the 
"".

So, to check for that you have to do something like this right?

if ( $var != '' ) {}
if ( strlen($var) > 0 ) {}
if ( !empty($var) ) {}
... a number of other ideas come to mind, but

none of them will work, because they will always product a E_NOTICE warning.

You COULD always use empty() prefixed with an @ to quiet the E_NOTICE,


Stut wouldn't do that... especially not after calling isset() a waste of
cycles. using the @ to suppress warnings/errors still invokes the error
system, and that includes any error handler you've custom hooked.

Maybe Stut just writes bad code ;) ;)

Cheers,
Rob.

I wouldn't say bad code, but I might say exceptionally noisy code  :P

--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Stut

Jim Lucas wrote:

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST['var'] 
= ""

and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}


The isset is a pointless waste of cycles.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread Jim Lucas

Richard Kurth wrote:

What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like 
if (isset($_REQUEST['var'])) {

}
Put var has no data it still says it is set. Because $_REQUEST['var'] = ""
and isset thinks "" is set


I use this combination a lot:

if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}

--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-16 Thread tedd

At 12:16 PM -0500 4/15/07, Larry Garfield wrote:

If you want your syntax to be a bit simpler, I frequently use helper functions
along these lines:

function http_get_int($var, $default=0) {
  return isset($_GET[$var]) ? (int) $_GET[$var] : $default;
}

if (http_get_int('var') ==5) {
  // Do stuff
}

Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE friendly.


Larry:

Slick.

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset

2007-04-15 Thread Buesching, Logan J
> how I understand:
> clause one: isset($_GET['var'])
> clause two: ($_GET['var'] == 'foo')
> if clause two is true, clause one MUST be true.
> if clause one is true, clause two could be true or false.
>
> means, if I look for solutions where ($_GET['var'] == 'foo') they wil
> lautomaticaly cover isset($_GET['var']) part.
> if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or
> !isset($_GET['var']).

If you are looking for 

isset($_GET['var'])

to return true if the value exists, but may be null, you can always use 

if (isset($_GET['var']) || is_null($_GET['var]))

Albeit, I'm unsure if this will generate a warning if $_GET['var']
doesn't exist for the is_null() call.  And in this case, I believe it
would be appropriate to ignore that one warning.

-Logan

-Original Message-
From: Larry Garfield [mailto:[EMAIL PROTECTED] 
Sent: Sunday, April 15, 2007 1:17 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] isset

On Sunday 15 April 2007 12:07 pm, [EMAIL PROTECTED] wrote:

> > of course it's your call whether you write/run code that spits out
> > E_NOTICEs all over the place due to usage of uninitialized vars.
>
> not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not
equal to
> 'foo', right?
>
>
> or I'm missing something here?
>
> I have E_NOTICE turned off. :)

And right there is your first mistake.  The only time to not have
E_NOTICE on 
is when you're using legacy code that isn't E_NOTICE compliant and you
don't 
have the time to upgrade it to be compliant.  Developing without
E_NOTICE 
means you're telling the computer "it's OK, let me just randomly guess
where 
this bug or security hole or random typo is".  *Bad* idea.  

*Always* develop in the tightest, most restricted, most nit-picky
setting you 
can get, regardless of the language.  

If you want your syntax to be a bit simpler, I frequently use helper
functions 
along these lines:

function http_get_int($var, $default=0) {
  return isset($_GET[$var]) ? (int) $_GET[$var] : $default;
}

if (http_get_int('var') ==5) {
  // Do stuff
}

Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE
friendly.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an
idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the
possession 
of every one, and the receiver cannot dispossess himself of it."  --
Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-15 Thread Larry Garfield
On Sunday 15 April 2007 12:07 pm, [EMAIL PROTECTED] wrote:

> > of course it's your call whether you write/run code that spits out
> > E_NOTICEs all over the place due to usage of uninitialized vars.
>
> not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to
> 'foo', right?
>
> how I understand:
> clause one: isset($_GET['var'])
> clause two: ($_GET['var'] == 'foo')
> if clause two is true, clause one MUST be true.
> if clause one is true, clause two could be true or false.
>
> means, if I look for solutions where ($_GET['var'] == 'foo') they wil
> lautomaticaly cover isset($_GET['var']) part.
> if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or
> !isset($_GET['var']).
>
> or I'm missing something here?
>
> I have E_NOTICE turned off. :)

And right there is your first mistake.  The only time to not have E_NOTICE on 
is when you're using legacy code that isn't E_NOTICE compliant and you don't 
have the time to upgrade it to be compliant.  Developing without E_NOTICE 
means you're telling the computer "it's OK, let me just randomly guess where 
this bug or security hole or random typo is".  *Bad* idea.  

*Always* develop in the tightest, most restricted, most nit-picky setting you 
can get, regardless of the language.  

If you want your syntax to be a bit simpler, I frequently use helper functions 
along these lines:

function http_get_int($var, $default=0) {
  return isset($_GET[$var]) ? (int) $_GET[$var] : $default;
}

if (http_get_int('var') ==5) {
  // Do stuff
}

Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE friendly.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-15 Thread afan
> Afan Pasalic wrote:
>>
>> Jochem Maas wrote:
>>> Richard Kurth wrote:
>>>
 What do you do when isset does not work? If I send data in a
 $_REQUEST['var'] like
 if (isset($_REQUEST['var'])) {
 }
 Put var has no data it still says it is set. Because $_REQUEST['var']
 = ""
 and isset thinks "" is set

>>>
>>> php -r ' $r = array("foo" => "");
>>> var_dump(isset($r["foo"]),empty($r["foo"]));'
>>>
>>> so empty() should give you the result your looking for  ...
>>> some tips:
>>>
>>> 1. generally use $_GET or $_POST in preference to $_REQUEST
>>> 2. be specific about your input validation, e.g.:
>>>
>>> if (isset($_GET['var']) && ($_GET['var'] == 'foo')) {
>>> echo "got it!";
>>> }
>>>
>> I always wondered about this. if $_GET['var'] == 'foo' is true, isn't
>> automatically isset($_GET['var']) true too?
>> I mean, isn't
>> if ($_GET['var'] == 'foo')
>> {
>> echo "got it!";
>> }
>> just enough?
>
> it doesn't cover the situation where $_GET['var'] doesn't exist,
> and using uninitialized var is not recommended.
>
> of course it's your call whether you write/run code that spits out
> E_NOTICEs all over the place due to usage of uninitialized vars.
>

not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to
'foo', right?

how I understand:
clause one: isset($_GET['var'])
clause two: ($_GET['var'] == 'foo')
if clause two is true, clause one MUST be true.
if clause one is true, clause two could be true or false.

means, if I look for solutions where ($_GET['var'] == 'foo') they wil
lautomaticaly cover isset($_GET['var']) part.
if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or
!isset($_GET['var']).

or I'm missing something here?

I have E_NOTICE turned off. :)

thanks.

-afan

>>
>> -afan
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-15 Thread Jochem Maas
Afan Pasalic wrote:
> 
> Jochem Maas wrote:
>> Richard Kurth wrote:
>>   
>>> What do you do when isset does not work? If I send data in a
>>> $_REQUEST['var'] like 
>>> if (isset($_REQUEST['var'])) {
>>> }
>>> Put var has no data it still says it is set. Because $_REQUEST['var'] = ""
>>> and isset thinks "" is set
>>> 
>>
>> php -r ' $r = array("foo" => ""); 
>> var_dump(isset($r["foo"]),empty($r["foo"]));'
>>
>> so empty() should give you the result your looking for  ...
>> some tips:
>>
>> 1. generally use $_GET or $_POST in preference to $_REQUEST
>> 2. be specific about your input validation, e.g.:
>>
>> if (isset($_GET['var']) && ($_GET['var'] == 'foo')) {
>>  echo "got it!";
>> }
>>   
> I always wondered about this. if $_GET['var'] == 'foo' is true, isn't
> automatically isset($_GET['var']) true too?
> I mean, isn't
> if ($_GET['var'] == 'foo')
> {
> echo "got it!";
> }
> just enough?

it doesn't cover the situation where $_GET['var'] doesn't exist,
and using uninitialized var is not recommended.

of course it's your call whether you write/run code that spits out
E_NOTICEs all over the place due to usage of uninitialized vars.

> 
> -afan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2007-04-14 Thread Jochem Maas
Richard Kurth wrote:
> What do you do when isset does not work? If I send data in a
> $_REQUEST['var'] like 
> if (isset($_REQUEST['var'])) {
> }
> Put var has no data it still says it is set. Because $_REQUEST['var'] = ""
> and isset thinks "" is set

php -r ' $r = array("foo" => ""); var_dump(isset($r["foo"]),empty($r["foo"]));'

so empty() should give you the result your looking for  ...
some tips:

1. generally use $_GET or $_POST in preference to $_REQUEST
2. be specific about your input validation, e.g.:

if (isset($_GET['var']) && ($_GET['var'] == 'foo')) {
echo "got it!";
}

> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2005-02-15 Thread Burhan Khalid
D_C wrote:
I often use this type of construct 

$cmd = $_POST['cmd'];
if ($cmd == null) { // do default
but this throws a notice if the ['cmd'] index is not defined. ugly.
using 

if (isset($_POST['cmd'] ) {
  $cmd = $_POST['cmd'];
} 

seems lengthy. is there a way around this?
http://www.php.net/array-key-exists
$cmd = array_key_exists('cmd',$_POST) ? $_POST['cmd'] : null;
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset

2005-02-15 Thread Richard Lynch
D_C wrote:
> I often use this type of construct
>
> $cmd = $_POST['cmd'];
> if ($cmd == null) { // do default
>
> but this throws a notice if the ['cmd'] index is not defined. ugly.
> using
>
> if (isset($_POST['cmd'] ) {
>   $cmd = $_POST['cmd'];
> }
>
> seems lengthy. is there a way around this?
>
> i tried using
> $cmd = @ $_POST['cmd'];
>
> to suppress errors but didnt seem to have ay effect.

You could maybe put the @ in front of the $cmd:
@$cmd = $_POST['cmd'];

However, I think it would be most clear to do:
$cmd = isset($_POST['cmd']) ? $_POST['cmd'] : NULL;

You can then rest assured that $cmd *IS* set in the rest of your script.

It's a bit lengthy, but at least it's all on one concise line, and you can
easily copy/paste and comment in/out the line.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset opposite

2004-11-16 Thread Dustin Krysak
Yeah as soon as I saw this example, I figured that was the case for 
example something like

if (!empty())
and so on.
d
On 16-Nov-04, at 5:26 PM, Robby Russell wrote:
On Tue, 2004-11-16 at 17:19 -0800, Dustin Krysak wrote:
Thanks!
perfect!
d
For future reference, just about any function that uses is at the
beginning should return a boolean result. So if (is_array()) can also 
be
checked with if (!is_array())

This should apply to all the php included functions that start with is.
-Robby
--
/***
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON  | www.planetargon.com
* Portland, OR  | [EMAIL PROTECTED]
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
*--- Now supporting PHP5 ---
/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] isset opposite

2004-11-16 Thread Robby Russell
On Tue, 2004-11-16 at 17:19 -0800, Dustin Krysak wrote:
> Thanks!
> 
> perfect!
> 
> d

For future reference, just about any function that uses is at the
beginning should return a boolean result. So if (is_array()) can also be
checked with if (!is_array())

This should apply to all the php included functions that start with is. 

-Robby
-- 
/***
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON  | www.planetargon.com
* Portland, OR  | [EMAIL PROTECTED]
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
*--- Now supporting PHP5 ---
/


signature.asc
Description: This is a digitally signed message part


Re: [PHP] isset opposite

2004-11-16 Thread Dustin Krysak
Thanks!
perfect!
d
On 16-Nov-04, at 4:13 PM, Robby Russell wrote:
On Tue, 2004-11-16 at 15:11 -0800, Dustin Krysak wrote:
Hi there.. I am pretty new to PHP, and I am familiar with php "isset"
option now i was wondering (I have looked at the PHP site - 
but
can not find it) how can you check if something is not set? I need to
test if a $_GET is not set (not just empty).

thanks in advance!
d
isset() returns a boolean.
so...try,
if (!isset($x))
--
/***
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON  | www.planetargon.com
* Portland, OR  | [EMAIL PROTECTED]
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
*--- Now supporting PHP5 ---
/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] isset opposite

2004-11-16 Thread Robby Russell
On Tue, 2004-11-16 at 15:11 -0800, Dustin Krysak wrote:
> Hi there.. I am pretty new to PHP, and I am familiar with php "isset" 
> option now i was wondering (I have looked at the PHP site - but 
> can not find it) how can you check if something is not set? I need to 
> test if a $_GET is not set (not just empty).
> 
> thanks in advance!
> 
> d
> 

isset() returns a boolean.

so...try,

if (!isset($x))


-- 
/***
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON  | www.planetargon.com
* Portland, OR  | [EMAIL PROTECTED]
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
*--- Now supporting PHP5 ---
/


signature.asc
Description: This is a digitally signed message part


Re: [PHP] isset opposite

2004-11-16 Thread Ryan King
On Nov 16, 2004, at 5:11 PM, Dustin Krysak wrote:
Hi there.. I am pretty new to PHP, and I am familiar with php "isset" 
option now i was wondering (I have looked at the PHP site - 
but can not find it) how can you check if something is not set? I need 
to test if a $_GET is not set (not just empty).
!array_key_exists('yourkey', $_GET);
-ryan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] isset opposite

2004-11-16 Thread Greg Donald
On Tue, 16 Nov 2004 15:11:39 -0800, Dustin Krysak
<[EMAIL PROTECTED]> wrote:
> how can you check if something is not set?

!isset()

-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset opposite

2004-11-16 Thread Matthew Sims
> Hi there.. I am pretty new to PHP, and I am familiar with php "isset"
> option now i was wondering (I have looked at the PHP site - but
> can not find it) how can you check if something is not set? I need to
> test if a $_GET is not set (not just empty).
>
> thanks in advance!
>
> d
>


I'm sure I'll be one of the many who says this:

!isset

The ! means not. You can use it with most of the functions like !empty
(not empty).

So you can use it like so:

if (!isset($_GET["var"])) {
  do stuff
}

-- 
--Matthew Sims
--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] ISSET problem with Form

2004-05-27 Thread Jay Blanchard
[snip]
I'm new to PHP, so how would I go about using sessions?
I assume one needs to update _SESSION['name'] = $name; with the state of
the
form and then use IF ?
Then I'm stuck again!
[/snip]

start here http://www.php.net/session

P.S. Always reply to the list, you may not get a response. Your e-mail
was redirected to my SPAM folder as an unknown. I just happened to see
it when looking for something else someone swore they sent me.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] ISSET problem with Form

2004-05-27 Thread Jay Blanchard
[snip]
I've had the script working with two states but can't get the third
state
working!!!
Any help or alternative ideas much appreciated as this is causing me a
serious headache!!!
[/snip]

Sessions would be a better way to handle this.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() and !=NULL

2004-03-28 Thread Dimiter Naydenov
David Risner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]> On Fri, 26 
Mar 2004 10:40:43 -0800, "Marcjon Louwersheimer"
> <[EMAIL PROTECTED]> said:
> > Is there an easier way to do
> > isset($variable) AND $variable != NULL
> > ? I use this alot in my if statements, and I was wondering if there's an
> > easier way to do it, maybe with a single function? Oh and another
> > question... how does if ($variable) work? When does it evaluate true?
> 
> Check out the is_null function.  Itd seems to combine the two.
> 
> http://www.php.net/manual/en/function.is-null.php
>and
> http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax

As Rasmus noted, (!empty($var)) is a complete aquivalent to (isset($var) && $var != 
null). I ran some more extensive tests which show the following:

class MyClass
{
  var $field = 123;
  function MyClass() {}
}

1. $x = null;
2. $y = 0;
3. $z = '';
4. $w = 'xyz';
5. $t = 123;
6. $o = new MyClass();
7. // $v is not set

1. isset($x) && $x != NULL: []
2. isset($y) && $y != NULL: []
3. isset($z) && $z != NULL: []
4. isset($w) && $w != NULL: [1]
5. isset($t) && $t != NULL: [1]
6. isset($o) && $o != NULL: [1]
7. isset($v) && $v != NULL: []

1. isset($x): []
2. isset($y): [1]
3. isset($z): [1]
4. isset($w): [1]
5. isset($t): [1]
6. isset($o): [1]
7. isset($v): []

1. !empty($x): []
2. !empty($y): []
3. !empty($z): []
4. !empty($w): [1]
5. !empty($t): [1]
6. !empty($o): [1]
7. !empty($v): []

1. is_null($x): [1]
2. is_null($y): []
3. is_null($z): []
4. is_null($w): []
5. is_null($t): []
6. is_null($o): []
Notice: Undefined variable: v in c:\web\test.php on line 62
7. is_null($v): [1] 

Also, as you see is_null($var) throws a notice when the variable is not defined.

Hope this helps ;)

Regards,
Dimiter

Re: [PHP] isset() and !=NULL

2004-03-26 Thread David Risner
On Fri, 26 Mar 2004 10:40:43 -0800, "Marcjon Louwersheimer"
<[EMAIL PROTECTED]> said:
> Is there an easier way to do
> isset($variable) AND $variable != NULL
> ? I use this alot in my if statements, and I was wondering if there's an
> easier way to do it, maybe with a single function? Oh and another
> question... how does if ($variable) work? When does it evaluate true?

Check out the is_null function.  Itd seems to combine the two.

http://www.php.net/manual/en/function.is-null.php
   and
http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax

-- 
David G. Risner
Software Engineer
California State University, Los Angeles
http://www.risner.org/david/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() and !=NULL

2004-03-26 Thread Robert Cummings
On Fri, 2004-03-26 at 13:46, Rasmus Lerdorf wrote:
> if(!empty($variable))

This will return false positives for cases where the variable has not
been set to null but HAS been set to the empty string or to a 0? This
isn't really the same as the OP requested. However, isset() also returns
false for variables assigned null values and so he is fine with just
isset() and skipping the check for != NULL.

Contrast the following code and output:

echo ' isset: ['.isset( $foo ).']'."\n";
echo '!empty: ['.(!empty( $foo )).']'."\n";

-->  isset: []
--> !empty: []

-

$foo = null;
echo ' isset: ['.isset( $foo ).']'."\n";
echo '!empty: ['.(!empty( $foo )).']'."\n";

-->  isset: []
--> !empty: []

-

$foo = 0;
echo ' isset: ['.isset( $foo ).']'."\n";
echo '!empty: ['.(!empty( $foo )).']'."\n";

-->  isset: [1]
--> !empty: []

-

$foo = 0.0;
echo ' isset: ['.isset( $foo ).']'."\n";
echo '!empty: ['.(!empty( $foo )).']'."\n";

-->  isset: [1]
--> !empty: []

-

$foo = '';
echo ' isset: ['.isset( $foo ).']'."\n";
echo '!empty: ['.(!empty( $foo )).']'."\n";

-->  isset: [1]
--> !empty: []

-

$foo = 'blah';
echo ' isset: ['.isset( $foo ).']'."\n";
echo '!empty: ['.(!empty( $foo )).']'."\n";

-->  isset: [1]
--> !empty: [1]

-

Cheers,
Rob.

> 
> On Fri, 26 Mar 2004, Marcjon Louwersheimer wrote:
> 
> > Is there an easier way to do
> > isset($variable) AND $variable != NULL
> > ? I use this alot in my if statements, and I was wondering if there's an
> > easier way to do it, maybe with a single function? Oh and another
> > question... how does if ($variable) work? When does it evaluate true?
> > -- 
> >   Marcjon

-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() and !=NULL

2004-03-26 Thread Rasmus Lerdorf
if(!empty($variable))

On Fri, 26 Mar 2004, Marcjon Louwersheimer wrote:

> Is there an easier way to do
> isset($variable) AND $variable != NULL
> ? I use this alot in my if statements, and I was wondering if there's an
> easier way to do it, maybe with a single function? Oh and another
> question... how does if ($variable) work? When does it evaluate true?
> -- 
>   Marcjon
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] isset() question

2004-02-16 Thread Ford, Mike [LSS]
On 15 February 2004 18:30, Richard Davey wrote:

> I feel the book you're learning from might not be the best out there!
> Especially as it uses the horrible if : else : endif notation,

I'd have to disagree with you on that one -- personally I think that's a very elegant 
and useful syntax, and all the scripts written for my applications use it.

However, this is a matter of personal opinion, and the choice between the colonified 
syntax and the various brace styles should be down to what suits *you* best.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() question

2004-02-15 Thread Jason Wong
On Monday 16 February 2004 02:30, Richard Davey wrote:

> I feel the book you're learning from might not be the best out there!
> Especially as it uses the horrible if : else : endif notation,
> includes code on the same line as the PHP tags themselves 

What is horrible about that style? IMO doing this:



 [... a bunch of HTML ...]




looks a lot neater than:



 [... a bunch of HTML ...]



But whichever style a book chooses to use should not impact on one's decision 
as to whether it is a good book or not. I have not seen the book in question 
so I've no idea whether I would find it good or bad.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
There's another way to survive.  Mutual trust -- and help.
-- Kirk, "Day of the Dove", stardate unknown
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() question

2004-02-15 Thread Anthony Ritter
- Original Message -
From: "Richard Davey" <[EMAIL PROTECTED]>

> Hello Anthony,

> I feel the book you're learning from might not be the best out there!
> Especially as it uses the horrible if : else : endif notation,
> includes code on the same line as the PHP tags themselves and is
> teaching you to code with register globals on. Is the book still on
> sale? (i.e. did you buy it recently) or was it something you've had
> for a while/got 2nd hand?

> Best regards,
>  Richard Davey
>  http://www.phpcommunity.org/wiki/296.html

Thank you for the reply Richard.

Yes. The book is on sale at:

www.sitepoint.com

also, at amazon, b and n, etc.

In fact, it's now in it's second edition by Kevin Yank.

It's not a bad book - quite readable to a newbie like myself - but when I
ran that code it didn't jive with that function call.  To make sure, I
downloaded it from their site and ran it again - and the same thing
happened.

Thank you for your help.

TR






---
[This E-mail scanned for viruses by gonefishingguideservice.com]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset() question

2004-02-15 Thread Richard Davey
Hello Anthony,

Sunday, February 15, 2004, 4:43:12 PM, you wrote:

AR> Why doesn't the call to !isset() with the negation mark loads the next page
AR> when a name is not entered?

Because it's using isset() in the wrong capacity.

isset() does not check to see if a variable HAS a value, it checks to
see if the variable exists.

The variable in the code you posted will always exist, so the use of
isset() is redundant and should be changed for something like empty as
you noted. Stick the following in the top of your code to see:

";
print_r($_GET);
echo "";
?>

I feel the book you're learning from might not be the best out there!
Especially as it uses the horrible if : else : endif notation,
includes code on the same line as the PHP tags themselves and is
teaching you to code with register globals on. Is the book still on
sale? (i.e. did you buy it recently) or was it something you've had
for a while/got 2nd hand?

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset bug?

2003-08-22 Thread Robert Cummings
This should help:

http://www.php.net/manual/en/function.array-key-exists.php

Cheers,
Rob.


On Fri, 2003-08-22 at 13:26, Curt Zirzow wrote:
> * Thus wrote Christian Calloway ([EMAIL PROTECTED]):
> > Ok, here's the deal. I like to use $_GET and $_POST variables without values
> > to notify my scripts that some action must be taken. For example, given the
> > following URL:
> > 
> > http://blahdomain/blah.php?productid=1&edit
> > 
> > or given the following form element:
> > 
> > 
> 
> simply add a value="1" and it will fix your problem.
> 
> > 
> > My blah.php script will check if edit set using the following line:
> > 
> > if (isset($_REQUEST["edit"]))
> > {
> > ..
> > }
> > 
> > and then it will take the appropriate actions (lets just say its updating a
> > record in the database). Locally I am running PHPv4.3.2, and everything
> > works fine. I have been working on a large web-based application for the
> > last month, and yesterday I put it up live. Our host unfortunately runs
> > PHPv4.2.1 and I have no access to the conf files (those bastards) and
> > globals are set to on. Low and behold, the isset function returns false when
> > a $_POST or $_GET variable is passed but contains no value, which would be
> > exactly the same thing as checking the variable itself:
> > 
> 
> 
> Curt
> -- 
> "I used to think I was indecisive, but now I'm not so sure."
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
-- 
.-.
| Worlds of Carnage - http://www.wocmud.org   |
:-:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.|
`-'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset bug?

2003-08-22 Thread Christian Calloway
What I was trying to avoid is exactly that. It would require changing links
and hidden fields throughout the entire application, which would take hours
to track down. I am looking for a nice lazy and easy fix.


"Curt Zirzow" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> * Thus wrote Christian Calloway ([EMAIL PROTECTED]):
> > Ok, here's the deal. I like to use $_GET and $_POST variables without
values
> > to notify my scripts that some action must be taken. For example, given
the
> > following URL:
> >
> > http://blahdomain/blah.php?productid=1&edit
> >
> > or given the following form element:
> >
> > 
>
> simply add a value="1" and it will fix your problem.
>
> >
> > My blah.php script will check if edit set using the following line:
> >
> > if (isset($_REQUEST["edit"]))
> > {
> > ..
> > }
> >
> > and then it will take the appropriate actions (lets just say its
updating a
> > record in the database). Locally I am running PHPv4.3.2, and everything
> > works fine. I have been working on a large web-based application for the
> > last month, and yesterday I put it up live. Our host unfortunately runs
> > PHPv4.2.1 and I have no access to the conf files (those bastards) and
> > globals are set to on. Low and behold, the isset function returns false
when
> > a $_POST or $_GET variable is passed but contains no value, which would
be
> > exactly the same thing as checking the variable itself:
> >
>
>
> Curt
> -- 
> "I used to think I was indecisive, but now I'm not so sure."



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset bug?

2003-08-22 Thread Curt Zirzow
* Thus wrote Christian Calloway ([EMAIL PROTECTED]):
> Ok, here's the deal. I like to use $_GET and $_POST variables without values
> to notify my scripts that some action must be taken. For example, given the
> following URL:
> 
> http://blahdomain/blah.php?productid=1&edit
> 
> or given the following form element:
> 
> 

simply add a value="1" and it will fix your problem.

> 
> My blah.php script will check if edit set using the following line:
> 
> if (isset($_REQUEST["edit"]))
> {
> ..
> }
> 
> and then it will take the appropriate actions (lets just say its updating a
> record in the database). Locally I am running PHPv4.3.2, and everything
> works fine. I have been working on a large web-based application for the
> last month, and yesterday I put it up live. Our host unfortunately runs
> PHPv4.2.1 and I have no access to the conf files (those bastards) and
> globals are set to on. Low and behold, the isset function returns false when
> a $_POST or $_GET variable is passed but contains no value, which would be
> exactly the same thing as checking the variable itself:
> 


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset function problem

2003-07-10 Thread Jason Wong
On Thursday 10 July 2003 21:53, Denis L. Menezes wrote:
> I have the following code :
>
> Quote:
>
> if (isset($SenderEmailAddress)){
>   mail($mailTo, $mailSubject, $Message);
>   }
>
> Unquote
>
> All I want to do is that , if the $SenderEmailAddress is not entered, the
> mail() function should not run. However,
> if the $senderEmailAddress variable is not set, the error I get is "No
> recipient addresses found in header "
>
> Can someone help and tell me why I get this error?

Use if (!empty(...)) instead. Depending on how you're getting your variable it 
may be set but empty.

And where are you getting $mailTo? Isn't that supposed to contain the 
recipients?


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Humor in the Court:
Q: ...and what did he do then?
A: He came home, and next morning he was dead.
Q: So when he woke up the next morning he was dead?
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset function problem

2003-07-10 Thread sven
... or:

if(!empty($SenderEmailAddress))
{
...
}

Dean E. Weimer wrote:
> What about the rest of the code?  How is this variable defined?  I
> have had this happen in some code before, I found that the variable
> was set to "".  Try using:
>
> if (isset($SenderEmailAddress) && $SenderEmailAddress != "") {
>   mail($mailTo, $mailSubject, $Message);
> }
>
>> I have the following code :
>>
>> Quote:
>>
>> if (isset($SenderEmailAddress)){
>>   mail($mailTo, $mailSubject, $Message);
>>   }
>>
>> Unquote
>>
>> All I want to do is that , if the $SenderEmailAddress is not
>> entered, the mail() function should not run. However,
>> if the $senderEmailAddress variable is not set, the error I get is
>> "No recipient addresses found in header "
>>
>> Can someone help and tell me why I get this error?
>>
>> Thanks
>> Denis
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset function problem

2003-07-10 Thread Dean E. Weimer
What about the rest of the code?  How is this variable defined?  I have
had this happen in some code before, I found that the variable was set to
"".  Try using:

if (isset($SenderEmailAddress) && $SenderEmailAddress != "") {
  mail($mailTo, $mailSubject, $Message);
}

> I have the following code :
>
> Quote:
>
> if (isset($SenderEmailAddress)){
>   mail($mailTo, $mailSubject, $Message);
>   }
>
> Unquote
>
> All I want to do is that , if the $SenderEmailAddress is not entered, the
> mail() function should not run. However,
> if the $senderEmailAddress variable is not set, the error I get is "No
> recipient addresses found in header "
>
> Can someone help and tell me why I get this error?
>
> Thanks
> Denis
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Thanks,
  Dean E. Weimer
  http://www.dwiemer.org/
  [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] IsSet() and $_SESSION - BUG?

2003-06-30 Thread Jason Wong
On Tuesday 01 July 2003 12:46, John Manko wrote:
> Hello everyone.  I was able to determine what was causing my problem
> with session variables not being persitant across page requests.  I want
> to give you the full scope here, so I'm going to paste the code (and if
> you have any code tips, please let me know).
> I think the problem might be this (and I don't know why it should be,
> but maybe you can help):
> If you look at file2.php, you will see that ValidAdminLogin() contains
> the "global $_SESSION;" declaration., but that's not the problem.
> ValidAdminLogin()  calls a function ResetSessionVariables(), which also
> contains "global $_SESSION;".  When "global $_SESSION;" is present in
> ResetSessionVariables(), it seems as though the $_SESSION variables are
> not being preserved across page requests (notice that
> ResetSessionVariables() is called BEFORE the variables are set with the
> real data, but it's really $_SESSION['uid'] we are concerned with.)
> When I remove "global $_SESSION;" from  ResetSessionVariables(), all
> works fine across page request.  Also note that $_SESSION['uid'] is set
> when we return from the file2.php function calls as noted in the "echo"
> command.  So, why would a double global definintion negate $_SESSION?

I've not looked at your code but the fact is that "global $_SESSION;" is 
completely unnecessary. $_SESSION is a 'superglobal' that is available in all 
scopes.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Marxist Law of Distribution of Wealth:
Shortages will be divided equally among the peasants.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] IsSet() and $_SESSION - BUG?

2003-06-30 Thread John Manko
Hello everyone.  I was able to determine what was causing my problem 
with session variables not being persitant across page requests.  I want 
to give you the full scope here, so I'm going to paste the code (and if 
you have any code tips, please let me know). 
I think the problem might be this (and I don't know why it should be, 
but maybe you can help):
If you look at file2.php, you will see that ValidAdminLogin() contains 
the "global $_SESSION;" declaration., but that's not the problem.
ValidAdminLogin()  calls a function ResetSessionVariables(), which also 
contains "global $_SESSION;".  When "global $_SESSION;" is present in 
ResetSessionVariables(), it seems as though the $_SESSION variables are 
not being preserved across page requests (notice that 
ResetSessionVariables() is called BEFORE the variables are set with the 
real data, but it's really $_SESSION['uid'] we are concerned with.)
When I remove "global $_SESSION;" from  ResetSessionVariables(), all 
works fine across page request.  Also note that $_SESSION['uid'] is set 
when we return from the file2.php function calls as noted in the "echo" 
command.  So, why would a double global definintion negate $_SESSION?

 file1.php  -

if (!isset($_SESSION['uid'])) {
   if ( !ValidAdminLogin($_POST['adminid'],$_POST['adminpass'])){ 
forceadminlogin(); }   
} elseif ( !ValidAdminSession() ){
   // Not a valid admin session - redirect   
   forceadminlogin();
}   
?>



//We always get a value for this, but it get lost when we leave the page.
echo $_SESSION['uid'];
?>


Add Item



--- file2.php --


include "configvars.php";

function ValidAdminSession(){
   global $_SESSION;
   if ( isset($_SESSION['adminlogin']) ){ return 1; }
   else { return 0;}
}
function DisableClientCaching(){
   header("Expires: "  . gmdate("D, d M Y H:i:s") .  " GMT");   // 
Expire now
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  // 
always modified
   header("Cache-Control: no-store, no-cache, must-revalidate");  // 
HTTP/1.1
   header("Cache-Control: post-check=0, pre-check=0", false);// 
HTTP/1.0
   header("Pragma: no-cache");  // HTTP/1.0
}

function ResetSessionVariables(){

   // WHEN I REMOVE THIS LINE, EVERYTHING WORKS FINE
   // global $_SESSION;
 
   $_SESSION['uid'] = session_id();
   $_SESSION['username'] = '';
   $_SESSION['adminlogin'] = False;
   $_SESSION['fname'] = '';
   $_SESSION['lname'] = '';
   $_SESSION['email'] = '';
   $_SESSION['errormesg'] = '';
}

function ValidAdminLogin($user, $pass){

   global $_SESSION;
  
   include "DatabaseConnect.php";
   mysql_connect($DBAddress,$DBUser,$DBPassword);
   @mysql_select_db($DBDatabase) or die("ERROR");
   $query="SELECT * FROM adminuser WHERE user='" . $user ."' AND 
pass='" . md5($pass) . "'";
   $results = mysql_query($query);
   $num = mysql_numrows($results);   

   if ($num != 1){
   $returnvar = false;  // Make sure the user exist, and is only 
one (even though it's a unique SQL field)
   } else {
   ResetSessionVariables();

   $_SESSION['username'] = strtolower(formatformdata($user));
   $_SESSION['adminlogin'] = True;
   $_SESSION['fname'] = mysql_result($results,0,"fname");
   $_SESSION['lname'] = mysql_result($results,0,"lname");
   $_SESSION['email'] = mysql_result($results,0,"email");
   $_SESSION['uid'] = session_id();
   $returnvar = true;
   }
   return $returnvar;
   mysql_close();   
}

function forceadminlogin(){
   ResetSessionVariables();
   header("Location: AdminLogin.php");
}
function formatformdata($mystring){
   return addslashes(rawurldecode(chop($mystring)));   
}
?>



John Manko wrote:

I'm having a problem with the value that isset returns on $_SESSION
variables.  For some reason, even if $_SESSION['uid'] is set, isset
returns FALSE.  Here is the code:
-- file1.php ---
include "file2.php";
if (!isset($_SESSION["uid"])) {
// This first time $_SESSION["uid"] is check, we should
// end up in here.  However, ValidAdminLogin (next test)
// will set $_SESSION["uid"] so next time we will not
// get here.   
if ( !ValidAdminLogin($_POST["adminid"],$_POST["adminpass"]))
forceadminlogin();

} elseif ( !ValidAdminSession() )
forceadminlogin();
   

// this is done to show that $_SESSION["uid"] is being set
// but isset still returns false
echo $_SESSION["uid"];
-- file2.php ---
function ValidAdminLogin($user, $pass){

global $_SESSION;

if (The_MYSQL_Stuff_Is_NOT_OK) return false;
else
{
 session_start();
  $_SESSION["logged"] = true;
  $_SESSION["username"] = $user;
  $_SESSION["adminlogin"] = true;
  $_SESSION["fname"] = $fname;
  $_SESSION["lname"] = $lname;
  $_SESSION["email"] = $email;
  $_SESSION["uid"] = session_id();
  return t

Re: [PHP] isset()

2003-06-14 Thread Justin French
$output_fname = (isset($HTTP_POST_VARS['fname'])) ? $HTTP_POST_VARS['fname']
: '';

but the value WILL be set regardless... in this case i'd prefer:

if(isset($HTTP_POST_VARS['fname'])) { $output_fname =
$HTTP_POST_VARS['fname']; }


alternatively, I wrote a nice function to pluck out $_POST vars only if
they're set.  you could easily modify it to do $HTTP_POST_VARS instead of
$_POST


http://www.weberdev.com/get_example.php3?count=3662


Justin



on 15/06/03 10:44 AM, Daniel J. Rychlik ([EMAIL PROTECTED]) wrote:

> Why is my script autopopulating a "1" in the field names and not the orginal
> values ?
> Is it something to do with this statement ?
> $output_fname = isset($HTTP_POST_VARS['fname']);
> 
> Im declaring the var and using it in value field in my form.  I know that I
> missing something.  Its returning true when value is entered or when its not
> and placing a nice 1 in every field of my form.
> 
> Im thinking
> $output_fname = isset($HTTP_POST_VARS['fname']) ?  $HTTP_POST_VARS['fname']
> is the answer and ive tried for several hours to fix it.
> 
> -dan
> 
> - Original Message -
> From: "Daniel J. Rychlik" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, June 14, 2003 4:54 PM
> Subject: [PHP] isset()
> 
> 
> Having a bit of trouble with my forms returnin 1 in the form fields accept
> the data that was entered.  I think its because of this line,
> 
> $output_fname = isset($HTTP_POST_VARS['fname']);
> 
> I have a command action handler also that works in the same script and it
> seems to work well,  the only problem that Im having is passing back the
> error to the related filed that requires proper data.  I started just
> passing back a generic message so that I could get the routine down, once I
> get that I will be able to do more.
> 
> Here is a snipit of my code.
> 
> 
> 
> Please fix your errors
> 
>  
> echo $val; } ?>
> 
> 
> Please fill out form.
> 
> 
>  HTML STUFF.
> 
> 
> 
>  
> if (count($errors)) $has_errors = true;  // If we find errors,
> then flag
> if ($has_errors) $command ="data_check"  // Take us back to
> the data_check hidden field and set $has_errors
> true to display our errors at the top of our
> form.
> 
> ?>
> 
> This is really a 2 question issue, and I greatly appreicate you're time.
> This is my 2nd week learning PHP...
> 
> Thanks in advance,
> Dan
> 
> 
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset()

2003-06-14 Thread Daniel J. Rychlik
Why is my script autopopulating a "1" in the field names and not the orginal
values ?
Is it something to do with this statement ?
$output_fname = isset($HTTP_POST_VARS['fname']);

Im declaring the var and using it in value field in my form.  I know that I
missing something.  Its returning true when value is entered or when its not
and placing a nice 1 in every field of my form.

Im thinking
$output_fname = isset($HTTP_POST_VARS['fname']) ?  $HTTP_POST_VARS['fname']
is the answer and ive tried for several hours to fix it.

-dan

- Original Message - 
From: "Daniel J. Rychlik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 14, 2003 4:54 PM
Subject: [PHP] isset()


Having a bit of trouble with my forms returnin 1 in the form fields accept
the data that was entered.  I think its because of this line,

$output_fname = isset($HTTP_POST_VARS['fname']);

I have a command action handler also that works in the same script and it
seems to work well,  the only problem that Im having is passing back the
error to the related filed that requires proper data.  I started just
passing back a generic message so that I could get the routine down, once I
get that I will be able to do more.

Here is a snipit of my code.



Please fix your errors




Please fill out form.






This is really a 2 question issue, and I greatly appreicate you're time.
This is my 2nd week learning PHP...

Thanks in advance,
Dan





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Isset

2003-03-21 Thread Michael Sweeney
It depends on what you're trying to test.

If you want to find out if a variable is explicitly set to an empty
string, then isset() is not your answer. If you want find out if a
variable exists or is set to a non-null value, isset() will work.
However, it is not always going to give you the results you want in
checking submitted variables from a web page. For instance if an input
variable is set in the form with a value of "", isset() on that variable
will return true, even if it is empty. So if you testing for a value
being submitted, you'll get erroneous results. I've found empty() to be
a better test in  many cases than isset(), but it depends on what you're
trying to test. 

..michael..


On Fri, 2003-03-21 at 11:09, Liam Gibbs wrote:
> Responding to myself:
> 
> < 
> Often, I may have a 0 as values. While $ != "" doesn't recognize 0s (as in,
> that if would be false), isset() seems to work. Should I change all my $ !=
> "" to isset()s, or are there other factors I should check?>>
> 
> Conversely, what about empty(). Is that a better test for if a value could
> be 0 or 1 or 2 or ABC?
-- 
Michael Sweeney <[EMAIL PROTECTED]>
Verisity Design, Inc


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Isset

2003-03-21 Thread Liam Gibbs
Responding to myself:

<>

Conversely, what about empty(). Is that a better test for if a value could
be 0 or 1 or 2 or ABC?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset doesn't like "->"?

2002-11-10 Thread Michael Sims
On Sun, 10 Nov 2002 18:34:52 -0600, you wrote:

>PS: what is the proper term for the "->" syntax? pointer?

In Perl it's called an infix operator.  I think in PHP the technical
term for it is that "->" thingy... :-)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] isset doesn't like "->"?

2002-11-10 Thread UberGoober

> That's because isset() is expecting a variable, not a function. In your
> first example, you're trying to see if a function is set, not a
> variable. In your second example, you're doing it right...
>
> ---John Holmes...

That actually makes sense once I thought about it, a function referencing a
variable, or reference to a variable is in no way the same as a variable.

Thanks!



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] isset doesn't like "->"?

2002-11-10 Thread John W. Holmes
> I don't know if this is a bug, or what, but I get an error when trying
the
> following
> 
> if ( isset($adodbobject->Fields('myresult') ) ) { // do something }
>
> PHP throws an error ( not warning ) saying:
> Parse error: parse error, expecting `','' or `')'' in
/path/to/index.php
> on
> line 45
> 
> However, when I modify the isset to  look like this:
> 
> $_q = $adodbobject->Fields('myresult');
> if ( isset($_q) ) { // do something }
> 
> It works fine.

That's because isset() is expecting a variable, not a function. In your
first example, you're trying to see if a function is set, not a
variable. In your second example, you're doing it right...

---John Holmes... 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] isset($var) && !empty($var) same time!

2002-08-03 Thread Verdana Musone

I had given a try on your code, But it really output "1", a true value.

I used "PHP 4.2.2+Apache 1.3.26" under Win2K. And u?



- Original Message -
From: lallous
Sent: 2002Äê8ÔÂ3ÈÕ 16:19
To: [EMAIL PROTECTED]
Subject: Re: [PHP] isset($var) && !empty($var) same time!

because your variable is set already!

try doing this:

echo empty($asdadadadadadasd);
you will get a warning and have a FALSE value.


Elias
"Verdana Musone" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I always set error_reporting(E_ALL) oR error_reporting(2047), but i have
never got any errors when just use empty()
to determine whether a variable is set.

If the variable is: 0, null, not set or an empty string.
Then the empty() will return true.

It's unnecessary to call isset() first.

- Original Message -
From: lallous
Sent: 2002Äê8ÔÂ3ÈÕ 15:01
To: [EMAIL PROTECTED]
Subject: Re: [PHP] isset($var) && !empty($var) same time!

Just use empty() ?!

With error_reporting(E_ALL) you'll get a bunch of warnings if you only use
empty() w/o the isset() !

use isset() first and then check wheter empty or not empty!

so there is not one function that tests for empty and isset same time!?

Elias
"Analysis & Solutions" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Fri, Aug 02, 2002 at 04:48:17PM +0200, lallous wrote:
> >
> > function issne($var)
> > {
> >return isset($var) && !empty($var) ? true : false;
> > }
> >
> > is there is any builtin function that does that? (one function call).
>
> Yes.  Just use empty().  It automatically checks if the variable is:
>not set
>null
>an empty string
>zero
>
> If any of them are true, the empty() function returns true.  You don't
> need your function at all.
>
> --Dan
>
> --
>PHP classes that make web design easier
> SQL Solution  |   Layout Solution   |  Form Solution
> sqlsolution.info  | layoutsolution.info |  formsolution.info
>  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
>  4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.phpGet more from the Web.
FREE MSN Explorer download : http://explorer.msn.com




--  
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.phpGet more from the Web.  FREE MSN 
Explorer download : http://explorer.msn.com



  1   2   >