reason for a "Notice:.." on one site but not another? (Same code.)
reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 01:43:43 von Govinda
Hi sunday coders,
I've been using this kind of logic on one PHP site I work on to
display one thing or another depending on whether the form was
submitted or not:
if($_POST['UserWishesDateRange']) { //--line 79
echo'submitted';
} else {
echo'NOT submitted';
}
and it works great on that site.
But on another site it still works, but gives this error:
Notice: Undefined index: UserWishesDateRange in /home/vs/site/phvs/bl/
7solarsecrets/admin/trackingcode.html on line 79
I assume that is because the error display settings are set to a more
rigorous level in this latter site.
Is this correct?
(Both sites reside on servers where I am not the admin.)
------------
John Butler (Govinda)
govinda.webdnatalk@gmail.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 01:53:58 von Mari Masuda
On Aug 9, 2009, at 16:43, John Butler wrote:
> Hi sunday coders,
>
> I've been using this kind of logic on one PHP site I work on to
> display one thing or another depending on whether the form was
> submitted or not:
>
> if($_POST['UserWishesDateRange']) { //--line 79
> echo'submitted';
> } else {
> echo'NOT submitted';
> }
>
> and it works great on that site.
>
> But on another site it still works, but gives this error:
> Notice: Undefined index: UserWishesDateRange in /home/vs/site/phvs/
> bl/7solarsecrets/admin/trackingcode.html on line 79
>
> I assume that is because the error display settings are set to a
> more rigorous level in this latter site.
> Is this correct?
>
> (Both sites reside on servers where I am not the admin.)
>
> ------------
> John Butler (Govinda)
> govinda.webdnatalk@gmail.com
You could do something like:
if(isset($_POST['UserWishesDateRange'])) { //--line 79 or you could
use something like !empty($_POST['UserWishesDateRange'])
echo 'submitted';
} else {
echo 'NOT submitted';
}
This will check if $_POST['UserWishesDateRange'] is set to
something. You are getting the error message because $_POST
['UserWishesDateRange'] is not set if the form is not submitted. The
server where you don't get the error message probably just has error
reporting turned off.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 01:57:06 von James Colannino
John Butler wrote:
> if($_POST['UserWishesDateRange']) { //--line 79
> echo'submitted';
> } else {
> echo'NOT submitted';
> }
Try this instead:
if (isset('UserWishesDateRange'])) {
// [...stuff goes here...]
}
James
--
"Black holes are where God divided by zero." --Steven Wright
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 02:00:43 von Ben Dunlap
> But on another site it still works, but gives this error:
> Notice: Undefined index: UserWishesDateRange in
> /home/vs/site/phvs/bl/7solarsecrets/admin/trackingcode.html on line 79
>
> I assume that is because the error display settings are set to a more
> rigorous level in this latter site.
> Is this correct?
It's either the 'error_reporting' configuration directive that's
different between the two servers, or 'display_errors', or both.
On one server the E_NOTICE bit-field is set in 'error_reporting', and
it sounds like 'display_errors' is also set (unless you're seeing that
notice in a log file).
On the other server, one or the other of those things is not set (or
both of them aren't).
You can use call ini_get('error_reporting') and
ini_get('display_errors'), to see what they're set to on each server.
Or just create a small page that only calls phpinfo(), to see all
configuration directives.
Here's the write-up of the directives (one is right below the other):
http://us3.php.net/manual/en/errorfunc.configuration.php#ini .error-reporting
As others have pointed out, it's a good idea to call isset() on a
POST-variable before trying to get at its value. This will avoid a
notice being thrown.
Lately I've stopped touching $_POST directly and started using
filter_input() instead; this also avoids the problem and provides
several other benefits:
http://us2.php.net/manual/en/function.filter-input.php
The filter_* functions are only available in core since 5.2.0, though.
Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 02:16:35 von Phpster
Bastien
Sent from my iPod
--
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 02:18:27 von Phpster
On Aug 9, 2009, at 7:43 PM, John Butler
wrote:
> Hi sunday coders,
>
> I've been using this kind of logic on one PHP site I work on to
> display one thing or another depending on whether the form was
> submitted or not:
>
>
>
> and it works great on that site.
>
> But on another site it still works, but gives this error:
> Notice: Undefined index: in /home/vs/site/phvs/bl/7solarsecrets/
> admin/trackingcode.html on line 79
>
> I assume that is because the error display settings are set to a
> more rigorous level in this latter site.
> Is this correct?
>
> (Both sites reside on servers where I am not the admin.)
>
> ------------
> John Butler (Govinda)
> govinda.webdnatalk@gmail.com
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
You could also simply define / initialize the variable.
$UserWishesDateRange='';
> if($_POST['UserWishesDateRange']) { //--line 79
> echo'submitted';
> } else {
> echo'NOT submitted';
> }
Bastien
Sent from my iPod
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 02:26:25 von Govinda
--Apple-Mail-1-973845906
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
> http://us3.php.net/manual/en/errorfunc.configuration.php#ini .error-reporting
Thank you guys for the isset() heads up. And Ben, for this good
explanation of error reporting!
> As others have pointed out, it's a good idea to call isset() on a
> POST-variable before trying to get at its value. This will avoid a
> notice being thrown.
OK, and I can work around all this anyway, but I would love to get it
all in one line of code, that essentially says: (pseudocode)
if ($IamNotEmpty && $IamEqualto='T') {
(where those are both the same var)
>
> http://us2.php.net/manual/en/function.filter-input.php
> The filter_* functions are only available in core since 5.2.0, though.
OK, ..good to plant seeds, but since that server is PHP 4.3, I'll save
my brain now for until I can actually integrate that study.
------------
John Butler (Govinda)
govinda.webdnatalk@gmail.com
--Apple-Mail-1-973845906--
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 04:36:54 von Shawn McKenzie
John Butler wrote:
>> http://us3.php.net/manual/en/errorfunc.configuration.php#ini .error-reporting
>>
>
> Thank you guys for the isset() heads up. And Ben, for this good
> explanation of error reporting!
>
>> As others have pointed out, it's a good idea to call isset() on a
>> POST-variable before trying to get at its value. This will avoid a
>> notice being thrown.
>
> OK, and I can work around all this anyway, but I would love to get it
> all in one line of code, that essentially says: (pseudocode)
> if ($IamNotEmpty && $IamEqualto='T') {
> (where those are both the same var)
if(isset($_POST['UserWishesDateRange']) && $_POST['UserWishesDateRange']
== 'T') {
-- or --
$uwdr = $_POST['UserWishesDateRange'];
if(isset($uwdr) && $uwdr == 'T') {
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 06:41:08 von Govinda
> if(isset($_POST['UserWishesDateRange']) &&
> $_POST['UserWishesDateRange']
> == 'T') {
Thought I tried that. Apparently not exactly; it works now! Thanks.
I know it is clunky but I wanted to see how compact it could be done.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Samecode.)
am 10.08.2009 17:45:46 von Shawn McKenzie
John Butler wrote:
>> if(isset($_POST['UserWishesDateRange']) && $_POST['UserWishesDateRange']
>> == 'T') {
>
>
> Thought I tried that. Apparently not exactly; it works now! Thanks. I
> know it is clunky but I wanted to see how compact it could be done.
If you switch it around you'll get a notice because the IF evaluates
from left to right. So you just want to make sure you check isset() first.
This would throw a notice:
if($_POST['UserWishesDateRange'] == 'T' &&
isset($_POST['UserWishesDateRange'])) {
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 18:42:40 von Govinda
--Apple-Mail-2-1032420513
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
>>
> If you switch it around you'll get a notice because the IF evaluates
> from left to right. So you just want to make sure you check isset()
> first.
>
> This would throw a notice:
>
> if($_POST['UserWishesDateRange'] == 'T' &&
> isset($_POST['UserWishesDateRange'])) {
Aha! That must be what I tried and was still getting the notice!
Interesting that it works (without notice) if we check against the
isset () one first. It makes if() look more intelligent that I would
think... as if it saying, "good now that we've established that the
var isset, now is it also equal to '___'., as opposed to just, "is var
set, and is var equal to "___'.
--Apple-Mail-2-1032420513--
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 19:07:54 von Martin Scotta
--0016e647ee5e6fa2d10470cca07c
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Why do you all always use isset?
Why do you don't use array_key_exists instead? is it a more semantic
solution?
$key = 'UserWishesDateRange'; # just to make statement shorter
if( array_key_exists($key, $_POST ) && 'T' == $_POST[$key] )
{
echo ' the key exists... and it is a "T" '';
}
*isset*: Determine if a variable is set and is not NULL*
array_key_exists: *Checks if the given key or index exists in the array
On Mon, Aug 10, 2009 at 1:42 PM, John Butler
wrote:
>
>>> If you switch it around you'll get a notice because the IF evaluates
>> from left to right. So you just want to make sure you check isset()
>> first.
>>
>> This would throw a notice:
>>
>> if($_POST['UserWishesDateRange'] == 'T' &&
>> isset($_POST['UserWishesDateRange'])) {
>>
>
> Aha! That must be what I tried and was still getting the notice!
> Interesting that it works (without notice) if we check against the isset ()
> one first. It makes if() look more intelligent that I would think... as if
> it saying, "good now that we've established that the var isset, now is it
> also equal to '___'., as opposed to just, "is var set, and is var equal to
> "___'.
--
Martin Scotta
--0016e647ee5e6fa2d10470cca07c--
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 19:50:48 von Ralph Deffke
this is not "intelligence" its just pure math. the '&&' says if BOTH
expressions are true then the whole expression is true.
so if the first one is false, the whole is false, why checking the next one
in the underlaying C it would be something like this
{
if ( expression == false ) return false;
if ( expression == false) return false;
return true;
}
ralph
ralph_deffke@yahoo.de
"John Butler" wrote in message
news:9ADA6DF4-649C-4790-B51B-CC9CC0505CE0@gmail.com...
> >>
> > If you switch it around you'll get a notice because the IF evaluates
> > from left to right. So you just want to make sure you check isset()
> > first.
> >
> > This would throw a notice:
> >
> > if($_POST['UserWishesDateRange'] == 'T' &&
> > isset($_POST['UserWishesDateRange'])) {
>
> Aha! That must be what I tried and was still getting the notice!
> Interesting that it works (without notice) if we check against the
> isset () one first. It makes if() look more intelligent that I would
> think... as if it saying, "good now that we've established that the
> var isset, now is it also equal to '___'., as opposed to just, "is var
> set, and is var equal to "___'.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 20:02:16 von Eddie Drapkin
On Mon, Aug 10, 2009 at 1:07 PM, Martin Scotta wrot=
e:
> Why do you all always use isset?
> Why do you don't use array_key_exists instead? is it a more semantic
> solution?
>
>
>
> $key =3D 'UserWishesDateRange'; # just to make statement shorter
> if( array_key_exists($key, $_POST ) && 'T' == $_POST[$key] )
> {
> Â Â echo ' the key exists... and it is a "T" '';
> }
>
> *isset*: Determine if a variable is set and is not NULL*
> array_key_exists: *Checks if the given key or index exists in the array
>
>
> On Mon, Aug 10, 2009 at 1:42 PM, John Butler
> wrote:
>
>>
>>>> Â If you switch it around you'll get a notice because the IF evalu=
ates
>>> from left to right. Â So you just want to make sure you check isset=
()
>>> first.
>>>
>>> This would throw a notice:
>>>
>>> if($_POST['UserWishesDateRange'] Â == 'T' &&
>>> isset($_POST['UserWishesDateRange'])) {
>>>
>>
>> Aha! Â That must be what I tried and was still getting the notice!
>> Â Interesting that it works (without notice) if we check against the=
isset ()
>> one first. Â It makes if() look more intelligent that I would think=
.... as if
>> it saying, "good now that we've established that the var isset, now is i=
t
>> also equal to '___'., as opposed to just, "is var set, and is var equal =
to
>> "___'.
>
>
>
>
> --
> Martin Scotta
>
Two reasons:
1. isset() is orders of magnitude faster
2. The theory is, if a variable is null you don't care about it
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 20:27:21 von Govinda
--Apple-Mail-3-1038702397
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
>>>>
>>> If you switch it around you'll get a notice because the IF evaluates
>>> from left to right. So you just want to make sure you check isset()
>>> first.
>>>
>>> This would throw a notice:
>>>
>>> if($_POST['UserWishesDateRange'] == 'T' &&
>>> isset($_POST['UserWishesDateRange'])) {
>>
>> Aha! That must be what I tried and was still getting the notice!
>> Interesting that it works (without notice) if we check against the
>> isset () one first. It makes if() look more intelligent that I
>> would
>> think... as if it saying, "good now that we've established that the
>> var isset, now is it also equal to '___'., as opposed to just, "is
>> var
>> set, and is var equal to "___'.
> this is not "intelligence" its just pure math. the '&&' says if BOTH
> expressions are true then the whole expression is true.
>
> so if the first one is false, the whole is false, why checking the
> next one
> in the underlaying C it would be something like this
> {
> if ( expression == false ) return false;
> if ( expression == false) return false;
> return true;
> }
I would have thought both would have to be true on their own (without
notice) in order for the the combined expression to be true (without
notice). But Shawn pointed out that the order matters; if we check
for the var's value before checking if it isset then we get a notice,
but if the order is reversed, then we get no notice.
--Apple-Mail-3-1038702397--
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 20:29:43 von Andrew Ballard
On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffke wrote:
> this is not "intelligence" its just pure math. the '&&' says if BOTH
> expressions are true then the whole expression is true.
>
> so if the first one is false, the whole is false, why checking the next one
> in the underlaying C it would be something like this
> {
> if ( expression == false ) return false;
> if ( expression == false) return false;
> return true;
> }
>
> ralph
> ralph_deffke@yahoo.de
That's logically correct, and while PHP does implement this
"short-circuit" logic, not all languages do. In that regard, I
appreciate what John meant by saying it makes it look "more
intelligent." Some languages evaluate each of the conditions to their
respective boolean results before evaluating the logical operators.
Andrew
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 20:40:19 von Martin Scotta
--0016363107f3f64b890470cdea02
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
This "intelligence" is given by the laziness of the && operator.
$res = a() && b(); # if a() is false then b() does not evaluate
$res = a() & b(); # b() evaluates no matter a()'s result
so, order matters.
On Mon, Aug 10, 2009 at 3:29 PM, Andrew Ballard wrote:
> On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffke
> wrote:
> > this is not "intelligence" its just pure math. the '&&' says if BOTH
> > expressions are true then the whole expression is true.
> >
> > so if the first one is false, the whole is false, why checking the next
> one
> > in the underlaying C it would be something like this
> > {
> > if ( expression == false ) return false;
> > if ( expression == false) return false;
> > return true;
> > }
> >
> > ralph
> > ralph_deffke@yahoo.de
>
> That's logically correct, and while PHP does implement this
> "short-circuit" logic, not all languages do. In that regard, I
> appreciate what John meant by saying it makes it look "more
> intelligent." Some languages evaluate each of the conditions to their
> respective boolean results before evaluating the logical operators.
>
> Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Martin Scotta
--0016363107f3f64b890470cdea02--
AW: reason for a "Notice:.." on one site but not another? (Same code.)
am 10.08.2009 21:17:20 von Ralph Deffke
--0-1304298320-1249931840=:54526
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
the single & is a logical AND so a() NOR b() is evaluatet ! its usually use=
d on binary integer.=0Ae.g. 0x0001 & 0x0001 =3D 0x0001 equlals TRUE while 0=
x0002 & 0x0001 equals FALSE
so something like $a & $b guides to some =
very interisting results depending of their values=0Abut nothing u expect.=
while && tells 'evaluate' the expressions on both sites and combine i=
ts results in an AND operation.
thats why compilers and interpreters d=
o have a definition what value TRUE has.=0Aits very likely that TRUE is 1 a=
nd false is 0
lets say =0A$a =3D 1=0A$b =3D 1
then =0A$a & $b is =
1 or true and it would give the same like=0A$a && $b in that case
at t=
hat point its also to mention that an empty string in PHP is NOT == FAL=
SE
this gives the following result on an empty string:=0A$a =3D "";=0A=
isset( $a ) == TRUE
while=0A$a =3D null;=0Aisset( $a ) == FALS=
E;
for the same story there are the
==
===
and=0A!=3D=
=0A!===
operators
_________________ _______________=
=0AVon: Martin Scotta =0AAn: Andrew Ballard
rd@gmail.com>=0ACC: Ralph Deffke ; php-general@lists=
...php.net=0AGesendet: Montag, den 10. August 2009, 20:40:19 Uhr=0ABetreff: R=
e: [PHP] reason for a "Notice:.." on one site but not another? (Same code.=
)
This "intelligence" is given by the laziness of the && operator.=0A=
=0A$res =3D a() && b(); # if a() is false then b() does not evaluate=0A$res=
=3D a() & b(); # b() evaluates no matter a()'s result
so, order matte=
rs.
=0AOn Mon, Aug 10, 2009 at 3:29 PM, Andrew Ballard
...com> wrote:
On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffke
e@yahoo.de> wrote:=0A>>> this is not "intelligence" its just pure math. the=
'&&' says if BOTH=0A>>> expressions are true then the whole expression is =
true.=0A>>>=0A>>> so if the first one is false, the whole is false, why che=
cking the next one=0A>>> in the underlaying C it would be something like th=
is=0A>>> {=0A>>> if ( expression == false ) return false;=0A>>> if ( ex=
pression == false) return false;=0A>>> return true;=0A>>> }=0A>>>=0A>>>=
ralph=0A>>> ralph_deffke@yahoo.de=0A>=0A>That's logically correct, and whi=
le PHP does implement this=0A>>"short-circuit" logic, not all languages do.=
In that regard, I=0A>>appreciate what John meant by saying it makes it loo=
k "more=0A>>intelligent." Some languages evaluate each of the conditions to=
their=0A>>respective boolean results before evaluating the logical operato=
rs.=0A>=0A>>Andrew=0A>=0A>=0A>>--=0A>>PHP General Mailing List (http://www.=
php.net/)=0A>>To unsubscribe, visit: http://www.php.net/unsub.php=0A>=0A>=
=0A-- =0AMartin Scotta
--0-1304298320-1249931840=:54526--
Re: reason for a "Notice:.." on one site but not another? (Same
am 10.08.2009 22:22:58 von Adam Randall
That should be !== not !===
Adam.
On Mon, Aug 10, 2009 at 12:17 PM, Ralph Deffke wrote:
> for the same story there are the
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: reason for a "Notice:.." on one site but not another?(Same code.)
am 11.08.2009 08:57:20 von Ashley Sheridan
On Mon, 2009-08-10 at 15:40 -0300, Martin Scotta wrote:
> This "intelligence" is given by the laziness of the && operator.
>
> $res = a() && b(); # if a() is false then b() does not evaluate
> $res = a() & b(); # b() evaluates no matter a()'s result
>
> so, order matters.
>
> On Mon, Aug 10, 2009 at 3:29 PM, Andrew Ballard wrote:
>
> > On Mon, Aug 10, 2009 at 1:50 PM, Ralph Deffke
> > wrote:
> > > this is not "intelligence" its just pure math. the '&&' says if BOTH
> > > expressions are true then the whole expression is true.
> > >
> > > so if the first one is false, the whole is false, why checking the next
> > one
> > > in the underlaying C it would be something like this
> > > {
> > > if ( expression == false ) return false;
> > > if ( expression == false) return false;
> > > return true;
> > > }
> > >
> > > ralph
> > > ralph_deffke@yahoo.de
> >
> > That's logically correct, and while PHP does implement this
> > "short-circuit" logic, not all languages do. In that regard, I
> > appreciate what John meant by saying it makes it look "more
> > intelligent." Some languages evaluate each of the conditions to their
> > respective boolean results before evaluating the logical operators.
> >
> > Andrew
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
You get the same thing in bash. You call a bunch of commands to run in
series, but the next one only runs if it's predecessor was successful.
It's frequent to see this sort of command chain:
../configure && make && make install
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php