TheFilmGod Posted September 2, 2007 Share Posted September 2, 2007 Hey, I don't have a question about php coding, just about php logic. I want to create a registration page that self processes itself. if ( submit ... blah bla blah) else (show form) Problem is I want to have error reporting!! How can I use this structure to check for any errors and if there is an error, it shows the form and the error? ??? Maybe something like die(), but I"m not sure. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/ Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 You could simply have your form processing section create a multidimension array of errors. Then you would use something like... <?php if (isset($_POST['submit'])) { // process. } elseif (!isset($_POST['submit'] || isset($errors) { echo "<form>"; echo "<input type='text' name='uname'>" . isset($errors['uname']) ? " You didn't fill in the username" : ""; // etc etc } ?> Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/#findComment-339931 Share on other sites More sharing options...
TheFilmGod Posted September 2, 2007 Author Share Posted September 2, 2007 I'm starting to get it. But I'm a bit confused with the elseif. I know what it does but I thought in php only either if, elseif, or else can be executed and not two of them... Or am I wrong? Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/#findComment-339933 Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 Nope. You'd be wrong. An elseif will execute as long as the condition is met. Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/#findComment-339940 Share on other sites More sharing options...
LiamProductions Posted September 2, 2007 Share Posted September 2, 2007 You could use a If then if that works put a If inside and use else after that if to say like Username not taken. Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/#findComment-339975 Share on other sites More sharing options...
Crew-Portal Posted September 2, 2007 Share Posted September 2, 2007 if is the first thing to be tried to get excuted! if you have lets say 10 if statement and they all equal true then you get the equivalence of all 10 statements! if you have 1 if statement and 10 ifelse then it sees if the first if statement is true and if not then it goes through the list until it finds on that is ture, then excecutes it and dies the script not allowing the others to excecute even if tru. If you have an if, 100 ifelse and an else, it sees if the if is true if not it looks at all the elseif's and if none of those are true then it excicutes the else Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/#findComment-340085 Share on other sites More sharing options...
Neptunus Maris Posted September 2, 2007 Share Posted September 2, 2007 if (!isset($_POST[submit])) { $show_form = "yes"; } elseif (isset($_POST[submit])) { //do process } //end if if ($show_form == "yes") { $display = "<form ... } //end if Use $_SERVER[php_SELF] for the form action then print the display code later in html <html> <head> ... </head> <body> <?php print "$display"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/67672-no-php-code-but-php-logic/#findComment-340090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.