error messages wants to display below the textbox

Discussion in 'PHP' started by kumar84, Jun 25, 2007.

  1. #1
    I want to display the error message below the text box
    for example in the Username and password text box i didnt enter any thing means the message Enter the Username and Enter the password wants to display below the Username and password textbox respectively


    can anybody knows the script for this
     
    kumar84, Jun 25, 2007 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You will probably have to stick the error message in a session or in the url when you redirect.
     
    MMJ, Jun 25, 2007 IP
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    not necessarily.

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
     </head>
     <body>
      <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
        <p>
          <label for="username">username: </label>
    	  <input type="text" size="30" value="username" name="username" id="username" />
    	</p>
    	<p>
          <label for="password">password: </label>
    	  <input type="password" size="30" value="password" name="password" id="password" />
    	</p>
    	<p>
    	  <input type="submit" value="login" name="submit" />
    	</p>
      </form>
    
      <?php
    	if ( isset($_POST['username']) && isset($_POST['password']) )
    	{
    		if ( $_POST['username'] == "test" && $_POST['password'] == "test" )
    		{
    			?>
    				<h2>Redirecting you to the member page</h2>
    			<?php
    		}
    		else
    		{
    			?>
    				<h2 style="color:red;">Incorrect username and or password</h2>
    			<?
    		}
    	}
      ?>
     </body>
    </html>
    
    PHP:
     
    ansi, Jun 25, 2007 IP
  4. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Was assuming the form action wasn't on the same page. ;)
     
    MMJ, Jun 26, 2007 IP
  5. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #5
    even then all you would need is a simple $_GET[] to determine if the user has showd up here in error. they goto the processing page after logging in, on an invalid pass they get sent back to login.php?q=e or something and voila, error.
     
    ansi, Jun 26, 2007 IP
  6. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thats what I was talking about. :)
     
    MMJ, Jun 26, 2007 IP