Re: How to ovoid Undefined Variable error

From: Date: Mon, 30 Oct 2000 03:48:36 +0000
Subject: Re: How to ovoid Undefined Variable error
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-22603@lists.php.net to get a copy of this message
Get Now writes: > > I tried, but no luck :-(, Now the warning is moved from line 3. to line > 1 as expected. the line where I initialized to temp. > > Ex: > 1. $Temp=$Contact; > 2. $Contact=$Temp; > 3. If($Contact) > 4. { > .. > } > > regards, > SK Sorry, I should have been more specific--you need to initialize it to some constant value, not another undefined variable: for instance, if it hasn't been set by the form (use isset() to check), then initialize it to, say, 0 or the empty string: <?php if (!isset($Contact)) { $Contact = 0; } .... if ($Contact) { .... } ...etc... ?> You should also check out empty() to see if that would help you out. Hope this helps, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#22603) next »