convert variables to lowercase before comparing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    convert variables to lowercase before comparing

    i need to know how can i compare two strings one from database uppercase ex:'SmaRtic' and the other lower case ex:'smartic'.

    that is my code when the user post his data :

    [PHP]$QUERY = mysql_query("SE LECT User FROM users WHERE User='$User'");
    $R = mysql_fetch_ass oc($QUERY);
    if(strtolower($ R['User']) == $User){
    $errors['username']='Someone has already chosen that username. Please choose another one!.';
    }[/PHP]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by smartic
    i need to know how can i compare two strings one from database uppercase ex:'SmaRtic' and the other lower case ex:'smartic'.

    that is my code when the user post his data :

    [PHP]$QUERY = mysql_query("SE LECT User FROM users WHERE User='$User'");
    $R = mysql_fetch_ass oc($QUERY);
    if(strtolower($ R['User']) == $User){
    $errors['username']='Someone has already chosen that username. Please choose another one!.';
    }[/PHP]
    Does that not work?
    It looks like it should..

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      Originally posted by smartic
      [PHP]$QUERY = mysql_query("SE LECT User FROM users WHERE User='$User'");
      $R = mysql_fetch_ass oc($QUERY);
      if(strtolower($ R['User']) == $User){
      $errors['username']='Someone has already chosen that username. Please choose another one!.';
      }[/PHP]
      How about instead trying:

      [PHP]$QUERY = mysql_query("SE LECT User FROM users WHERE User='$User'");
      $R = mysql_fetch_ass oc($QUERY);
      if(strtolower($ R['User']) == $User){
      echo('Someone has already chosen that username. Please choose another one!');
      }[/PHP]

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        [php]if(strtolower($ R['User']) == strtolower($Use r))[/php]

        Comment

        • smartic
          New Member
          • May 2007
          • 150

          #5
          it work when i use this code why ?
          [PHP]
          SELECT `user` FROM `users` WHERE `user` = CONVERT( cp1256 'smartic' USING utf8 ) [/PHP]

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Originally posted by smartic
            it work when i use this code why ?
            [PHP]
            SELECT `user` FROM `users` WHERE `user` = CONVERT( cp1256 'smartic' USING utf8 ) [/PHP]
            That is not lowercase conversion or comparison.

            Ronald

            Comment

            Working...