isset not functioning
am 03.08.2009 19:08:08 von Allen McCabe
--00163646d6dc6695c404703fd0ec
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
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?
--00163646d6dc6695c404703fd0ec--
Re: isset not functioning
am 03.08.2009 19:11:44 von 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:657acef20908031008nc2c29cdo3e13733bc6f29d1a@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: isset not functioning
am 03.08.2009 19:13:10 von 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 =3D $_REQUEST['firstname'];
> Â } else {
> Â $name =3D 'Sir or Madam';
> }
>
> I also tried adding an underscore to $RESULT (I got the code for this fro=
m a
> php.net comment on the manual), to make it $_RESULT, but this doesn't see=
m
> to be a pre-set function, and it still does not make it work. I am guessi=
ng
> 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: isset not functioning
am 03.08.2009 19:19:01 von 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: isset not functioning
am 03.08.2009 19:23:09 von Steve Brown
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
> =A0$name =3D $_REQUEST['firstname'];
> =A0} else {
> =A0$name =3D '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 =3D $_POST['firstname'];
} else {
$name =3D '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: isset not functioning
am 03.08.2009 19:28:12 von jenai tomaka
--_cbc56ca6-abd7-46e1-8736-547b7937f53c_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Io=2C try do like this:
=20
You should use $_POST for the security=2C using $_REQUEST some users can pa=
ss a inject or someting to crash the aplication=2C and addslashes is for mo=
re security
=20
$firstName =3D addslashes($_POST['firstname'])=3B
=20
if(isset($firstName) && !empty($firstName)) {
$name =3D $firstName=3B
} else {
$name =3D 'Sir or Madam'=3B
}
Yuri Yarlei.
Programmer PHP=2C CSS=2C Java=2C PostregreSQL=3B
Today PHP=2C tomorrow Java=2C after the world.
Kyou wa PHP=2C ashita wa Java=2C sono ato sekai desu.
=20
> Date: Mon=2C 3 Aug 2009 10:08:08 -0700
> From: allenmccabe@gmail.com
> To: parham90@gmail.com
> CC: php-general@lists.php.net
> Subject: [PHP] isset not functioning
>=20
> I created a simple survey for my work website=2C most of the PHP is on my
> process.php document=2C which is referenced by a form on a seperate page
> containing the form with the method of "post".
>=20
> On my process.php page=2C the script obtains the field data using the
> $_REQUEST[] function.
>=20
> I have a small if statement to check to see if they filled out the
> 'firstname' field=2C and if they did not=2C to replace $name with "Sir or
> Madam". Unfortunately=2C $name always equals "Sir or Madam"=2C wether a v=
alue
> for "firstname" was entered or not.
>=20
> All the of the other instances of using $_REQUEST[] functions just fine=
=2C but
> don't make use of if or isset. Here is the code snippet:
>=20
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) {
> $name =3D $_REQUEST['firstname']=3B
> } else {
> $name =3D 'Sir or Madam'=3B
> }
>=20
> I also tried adding an underscore to $RESULT (I got the code for this fro=
m a
> php.net comment on the manual)=2C to make it $_RESULT=2C but this doesn't=
seem
> to be a pre-set function=2C and it still does not make it work. I am gues=
sing
> the user neglected to define $RESULT in his snippet=2C or I overlooked it=
..
>=20
> Can anyone see any problems with the code?
____________________________________________________________ _____
Novo Internet Explorer 8. Baixe agora=2C =E9 gr=E1tis!
http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=3DMS N%3BHotmail&utm=
_medium=3DTagline&utm_campaign=3DIE8=
--_cbc56ca6-abd7-46e1-8736-547b7937f53c_--