You are here: Re: Placing Errors On The Page « PHP Programming Language « IT news, forums, messages
Re: Placing Errors On The Page

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация