Debug for substr

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyberlei
    New Member
    • Sep 2007
    • 28

    #1

    Debug for substr

    it will have two alert messages display one after one. should be like if the first str has been handle then only display the second alert. please help and many thanks

    [CODE=php]
    if(substr($sn,0 ,1) == "S" && substr($add,0,2 ) == "00")
    {
    else
    {
    $message="Must Be Start With S";
    echo '<script>alert( "Must Be Start With S");</script>';
    }
    {
    $message="Must Be Start With 00";
    echo '<script>alert( "Must Be Start With 00");</script>';
    }
    }
    [/CODE]
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    If I understand correctly, you want to validate some input, and display warnings if they are incorrect?

    Do you mean something like this?
    [code=php]
    if(substr($sn,0 ,1) != "S") {
    echo '<script>alert( "Your input must start with S");</script>';
    }
    else if(substr($add, 0,2) != "00") {
    echo '<script>alert( "Your input must start with 00");</script>';
    }
    else {
    # The input fields are valid. Do whatever you want to do.
    }
    [/code]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, cyberlei.

      You need to re-balance your curly braces.

      The proper syntax of an if ... else is:
      [code=php]
      if( $condition )
      {
      // Do this if $condition is true.
      }
      else
      {
      // Do this if $condition is false.
      }
      [/code]

      Comment

      • cyberlei
        New Member
        • Sep 2007
        • 28

        #4
        Thank you so much guys.working well now

        Comment

        Working...