Hopefully a simple php problem ( exit() function)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monty
Forum Newbie
Posts: 8
Joined: Sat Jun 18, 2005 10:41 pm

Hopefully a simple php problem ( exit() function)

Post by Monty »

Hello,

I'm making a login system in php.
In my registration form, after i press submit button, i do some checks for valid email adres, password safety, etc..
Now if for example the users email adres is not valid, i execute this:

die('Invalid e-mail address.');

This php code is located in a html. The problem is that all the html code after the DIE function does not display... So the table looks completely messed up.
Is there a way to jump out of php code, but still render the remaining html below the code?


Thank you.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Instead of die, use some conditionals:

Code: Select all

if (everything in forum is valid) {
  // do registration
} else {
  echo 'Invalid xxx';
}
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

There are many ways. Post your code and we'll help.

Code: Select all

if($xyz == 'abc')
echo '<b>MY HTML</b>';
else
echo '<I>Nope</I>';
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Simply put, seperate your application code from your display code. That way, if you hit a problem while processing your data, you can throw a message without worrying about data you've already echo'd.
Monty
Forum Newbie
Posts: 8
Joined: Sat Jun 18, 2005 10:41 pm

Post by Monty »

OK
great!
using echo seems to make more sense for this :)

Thanx peoples
Post Reply