Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Changing error message for form validation

$
0
0

Hey guys. I have admin page that just says "Welcome. Please enter your username and password".

 

I am trying to change that message if the username and password is empty or if it is not correct.

 

Currently this is what I have ..

$message = "<span style=\"font-size:14px;\"><strong>Welcome </strong></span>!<br>
    Please enter your username and password to log in";

if(isset($_POST['submit'])) {
    
    
     $errors = array();
     $field_name = array('username','password');
      if(empty($_POST[$field_name]) || !isset($_POST[$field_name])) {
    $errors[] = "Please enter a username or password";
      }

If they enter the wrong username and password I have the following

if(mysql_num_rows($result) == 1) {
	//Redirect to Admin Page
// Success	
     } else {
         $errors[] = "Sorry your username or password is incorrect.<br />";
     }


And right above the username and password form I am displaying the following  welcome message

  <div id="login_msg">
    <?php   if(!empty($message)) {echo $message."<br>" ;}

    foreach ($errors as $message) {
        echo $message;
    
 }

Right now its just being appended to the actual $message. How can I completely change the text?? Thanks for your help!


Viewing all articles
Browse latest Browse all 13200

Trending Articles