Undeclared Variable warnings

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
credence
Forum Newbie
Posts: 2
Joined: Mon Aug 04, 2003 4:01 pm

Undeclared Variable warnings

Post by credence »

OK here is the deal. I have an input form with check boxes. And the value that is submitted to the database has to be Yes or No. So in my php submission code I have an error checking code that says

If($blah=="") {
$blah="no"
}

however whenver I submit with blah not checked it gives me an undeclared variable warning I would like to get rid of it. Not sure if it would help but I can't change the Post to a Get because the person I am doing this for would rather not have the information in the url.

Thanks in advance,

Jeff
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Code: Select all

<?php

If($blah == ""){ 
$blah="no";
echo $blah;
}

?>
make sure you close things --> $blah="no";
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

It would have given a parse error if he had forgotten that semicolon - it's more likely that he just retyped a snippet of his code on-the-fly, thus disregarding perfection.

Try this instead:

Code: Select all

If(!isset($blah)){
$blah="no";
}
credence
Forum Newbie
Posts: 2
Joined: Mon Aug 04, 2003 4:01 pm

Post by credence »

to the 2nd guy to reply thanks a bunch. you hit my problem right on the money. Sorry for my mistyping my code. never new isset existed until now
Post Reply