|
Posted by Bauglir on 10/04/96 11:08
It's common mistake what you are doing...
the first thing should be to test if there is such key in array:
if (array_key_exists('cmd',$_POST))
{
}
this means to test it the variable exists, then you can test if it was set
Brona
Chris W. Parker wrote:
> M. Sokolewicz <mailto:tularis@php.net>
> on Tuesday, February 15, 2005 8:25 AM said:
>
>
>>>seems lengthy. is there a way around this?
>>>
>>>i tried using
>>>$cmd = @ $_POST['cmd'];
>>>
>>>to suppress errors but didnt seem to have ay effect.
>>>
>>
>>still
>>if(isset($_POST['cmd'])) {
>> $cmd = $_POST['cmd'];
>>}
>>
>>is the only (really) correct way. All others throw notices of
>>undefined indices, which you *should not* ignore! You can't shorten
>>it, you can't even wrap it in a function... it's simply tough luck
>
>
> Please correct me if I'm wrong (and maybe this is what you mean by
> "(really)") but I think even Rasmus recommends:
>
> <?php
>
> if(!empty($_POST['cmd']))
> {
> // stuff
> }
>
> ?>
>
> I'm using the following code to test this:
>
> <?php
>
> error_reporting(E_ALL);
>
> if(!empty($_POST['cmd']))
> {
> echo "set and not empty<br />";
> }
> else
> {
> echo "empty and/or not set<br />";
> }
>
> ?>
>
>
>
>
> Chris.
>
--
s pozdravem
Bronislav Klucka
----------=[ pro2-soft.com ]=----------
http://pro2-soft.com
Bronislav.Klucka@pro2-soft.com
+420 605 58 29 22
* webove aplikace
* software na zakazku
---------------------------------------
[Back to original message]
|