Writing a condition for a variable which stores text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitz06
    New Member
    • Nov 2012
    • 3

    Writing a condition for a variable which stores text

    I have a form for registering. Am trying to prevent the person from entering too much of text for username and password but getting an error.

    my code is:

    Code:
    $uLength = strlen($regusername);
    $pLength = strlen($regpassword);
    if ($uLength >= 7 && $uLength <= 20)
    	{
    	$errorMessage = "";
    	}
    else 
    	{
    	$errorMessage = $errorMessage."Username must be between 7 and 20 characters"."<br/>";
    	}
    
    if ($pLength >= 6 && $pLength <= 15)
    	{
    	$errorMessage = "";
    	}
    else 
    	{
    	$errorMessage = $errorMessage."Password must be between 6 and 15 characters"."<br/>";
    	}
    am getting an error on this line saying undeclared variable...

    $errorMessage = $errorMessage." Username must be between 7 and 20 characters"."<b r/>";


    Can you please help me out? Will be very thankful :)
    Last edited by Rabbit; Nov 7 '12, 07:44 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    It's a fairly clear error message. You need to declare the variable before trying to use it.

    Comment

    • nitz06
      New Member
      • Nov 2012
      • 3

      #3
      how do I declare it? because after this code am using it in a condition like if $errorMessage is blank then do this or else this. But am confused on how to declare the variable "$errorMessage" . I looked for it on the net but got more confused as to different answers. Please help me :)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Am trying to prevent the person from entering too much of text for username and password
        use the HTML attribute maxlength.

        Comment

        • nitz06
          New Member
          • Nov 2012
          • 3

          #5
          thanks for the replies... my code works now but I used some other codes.. neway thanks

          Comment

          Working...