Eiolon Posted November 28, 2007 Share Posted November 28, 2007 I have an error message that appears if the username or password field has not been filled out. The problem is it always appears in the upper left hand corner of the screen. How would I make it so I can control where in the layout the message appears? <?php // Verify that the username has been entered. if (empty($_POST['username'])) { $u = FALSE; echo 'You must enter a username.<br />'; } else { $u = escape_data($_POST['username']); } // Verify that the password has been entered. if (empty($_POST['password'])) { $p = FALSE; echo 'You must enter a password.<br />'; } else { $p = escape_data($_POST['password']); } ?> Thanks! Quote Link to comment Share on other sites More sharing options...
Orio Posted November 28, 2007 Share Posted November 28, 2007 There are many solutions. Here's one of them- Put all of you validation code in a function. This function will return a string containing an error if an error occurred. If no error occurred, the function will return boolean true. Then you call the function and get it's returned value into a variable $error. Then, you check: <?php $error = validation(); //The function that I was talking about if($error !== TRUE) //An error occurred, print the error in a nice format { echo "Welcome to my site!<br>"; echo "<center>".$error."</center>"; die; } //Continue your script here... (no error occurred) ?> Hope this helps. Orio. Quote Link to comment 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.