Checking post variables are set

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Transferring scripts

Post by Nunners »

I have a script which I wrote about 2 years ago, that uses post variables.

One of the things it checks for is, does the variable exist - i.e. is it NOT NULL.....

How can you do that, as when I try using it, it just tells me, with a warning error, that the varilable is undefined...?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Transferring scripts

Post by twigletmac »

Nunners wrote:I have a script which I wrote about 2 years ago, that uses post variables.

One of the things it checks for is, does the variable exist - i.e. is it NOT NULL.....

How can you do that, as when I try using it, it just tells me, with a warning error, that the varilable is undefined...?
Do you do:

Code: Select all

if (!$variable) {
   echo 'var not set';
} else {
   echo 'var is set';
}
if so change it to something like

Code: Select all

if (!isset($variable)) {
   echo 'var not set';
} else {
   echo 'var is set';
}
Using isset() or empty() should mean you don't get the variable undefined errors for the if statement.

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Transferring scripts

Post by twigletmac »

Do you do:

Code: Select all

if (!$variable) {
   echo 'var not set';
} else {
   echo 'var is set';
}
if so change it to something like

Code: Select all

if (!isset($variable)) {
   echo 'var not set';
} else {
   echo 'var is set';
}
Using isset() or empty() should mean you don't get the variable undefined errors for the if statement.

Mac
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Post by Nunners »

I have been using (!$var) but I'm now going through and doing !isset and it works... thanks for your help....
Post Reply