|
Posted by Kimmo Laine on 03/12/07 07:37
"mpar612" <mpar612@gmail.com> wrote in message
news:1173481330.522140.17500@30g2000cwc.googlegroups.com...
>I have code below (due to length I only included a portion). I am
> validating an email address. It checks to see if the email field is
> blank, in the proper format, etc... It prints errors to the screen and
> everything works perfectly, but the errors always print at the very
> top of the page and I am having difficulty moving those errors around
> so they fit nicely into the page design I have. Rather than printing
> the errors I tried assigning them to variables and printing them
> elsewhere on the page, but it didn't work and the errors did not try
> at all.
The prbolem is variable scope.
function foo(){
$x = 'HELLO WORLD!';
}
foo();
echo $x; // Print's nothing
Regardles of $x being assigned at foo(), nothing is echoed. Why? 'cos $x
belongs to variable scope of foo(), not main.
Solutions:
Bad solution: make $x global. Quick and dirty, don't try this at home.
Good solution: make the function return an array of errors and use the
returned array values to echo error messages.
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|