Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting Error Message To Display Near Top Of Page

    I have a registration form that I am building.

    All the PHP code for my error message is below the form code.

    Here is the code:

    Code:
    <?php
    if($_POST['submit'])
      { 
       $usernameD= mysql_query("SELECT * FROM realtor WHERE user_name = '$user_name_register'");
       
       if($first_name_register == "" OR $last_name_register == "" OR $email_register == "" OR $user_name_register == "" OR  $password_register == "") {
               $errors[] = "<h1>Please fill out all fields</h1>";}
    		else {
         if(mysql_num_rows($usernameD)>0){
    		 
    		 $errors[] = "<h1>Username taken</h1>";
    		 }
       
       if($user_name_register == "" OR strlen($user_name_register)<4){
         $errors[] = "<h1>Please enter a longer username</h1>";
      }
      
      if($password_register == "" OR strlen($password_register)<4){
         $errors[] = "<h1>Please enter a longer password</h1>";
      }
      
      if(!$errors) {
    	  $register = mysql_query("INSERT INTO realtor(realtor_id, user_name, password, first_name, last_name, address, city, state, zip, phone, email, mls_id)VALUES(NULL,'$user_name_register','$password_register','$first_name_register','$last_name_register','$address_register','$city_register','$state_register','$zip_register','$phone_register','$email_register','$mls_register');");
    	  if($register) {
    		  $to = $email_register;
    		  $subject = "Activate You Accout";
    		  $headers = "From: admin@sliceofthe80s.net";
    
    		  $body = "Hello $user_name_register,\n\nYou registered and need to activate your account.  Click the link below or paste it into the URL of your browser\n\nhttp://www.jeremyconrad.net/is696/activate.php?code=$code_register\n\nThanks!";
    		  if(!mail($to, $subject, $headers, $body))
    		  { echo "We could not sign you up at this time";}
    		  else {
    		 echo "<script type = 'text/javascript'>";
    		 echo "window.location.href = 'pre_register.php'";
    		echo "</script>";
    	  
      }
    	  }
      
    	  }
    	else {foreach($errors as $error){
    		echo "$error <br /><br />";
    		echo "<br />";
    		
    		}
    
    	}
    	
      }
      
      }
    The $errors[] variable is what displays the error message. Currently the error message is displayed at the bottom of the page below the "Register" button.

    Is there a way I can display the errors ($errors[]) variable in near the top of the page?

    I have <div class = "welcome"> and would like to display the error message inside that div tag.

    Thanks in advance for all advice/help.

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    What is handling the data? Is this done via jquery or is this file included in a larger file?

    Javascript would probably be what you need for this, or a reorganization in your php code (if this is included in another file).

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    146
    Thanks
    3
    Thanked 21 Times in 21 Posts
    The easiest solution is to add your output to a variable as opposed to echoing it. Then call your PHP scripts above your output. You can then echo each variable into its correct location..

  • #4
    New Coder
    Join Date
    Feb 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is what the $errors[] variable is for. Am I going about this the right way? How do I call the $errors variable in another location on the same page? I want to call the variable outside of the if($_POST['submit']) section of the code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •