Re: undefine variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2008-08-17 at 22:26 +0100, Ashley Sheridan wrote:
> Hi Michael,
> 
> It seems that you are trying to use the $selected_state variable in the
> code, but it hasn't been declared yet. To test if a variable exists, you
> can use the isset() function.
> 
> Also, there is a quick way of writing your if/else check on one line.
> Here's the changes:
> 
> foreach($state_list as $key=>$value)
> {
>         $sel = (isset($selected_state) && $selected_state ==
>         $key)?'selected="selected"':'';
>         echo "<option $sel value=\"$key\">$value</option>";
> }
> echo '</select>';
> ?>
> 
> (That's only two lines there inside the loop, just incase my email
> client breaks the line because of wordwrap.)
> 
> Obviously, if your code worked before, but now is not, it might be that
> some other change in your code is causing this error, and that
> introducing my change will only mask a larger logic error. You should go
> through your code to check where the $selected_state variable is meant
> to be declared to make sure it really is.
> 
> There is another explanation. If you are not in control of your hosting,
> it could be that they changed the error reporting level to show notices
> as well, which I believe aren't turned on by default on all hosting
> packages.


Heh, actually that wasn't the problem after all. Well php still yells @
me about it, but it does work. In fact someone on this list helped me
before, sorry if I can't remember your name who it was :).   But it
wasn't writing to the DB and I discovered I had to change the
permissions (it was a backup I had restored) and restart mysql.  But you
have a lot of useful information in your list, so I'll be keeping it.
-- 
Michael S. Dunsavage


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux