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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Case sensative mysql query.

    PHP Code:
    $user mysql_real_escape_string($_POST['username']);

    $Select "SELECT * FROM `users` WHERE `username` = '".$user."' AND `password` = '".$pass."'"
    I currently have this set up (thats just a snippet) however it says login okay if i enter either User, USER, user etc for the username, anyway i can make it case sensative so say User would login but user would fail?
    Last edited by tomharto; 07-26-2011 at 01:45 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,417
    Thanks
    68
    Thanked 102 Times in 101 Posts
    This is all the information I could find.

    case sensitivity comes from collation. so if the collation is set as cs (case sensitive) then your query condition will be CS as well.

    You could convert everything to lowercase to prevent this from happening.

    PHP Code:
    <?php
    $str 
    "Mary Had A Little Lamb and She LOVED It So";
    $str strtolower($str);
    echo 
    $str// Prints mary had a little lamb and she loved it so
    ?>

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    The OPs problem is case insensitivity which is what your script does as well. Best place to post this question would be the mysql forum.

  • #4
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Yeah i just thought maybe this is more of a MySql problem, too used to posting in PHP :P. Ill put it there see what the guys there have to say :P

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I don't think I've ever needed to perform a case sensitive comparison before, but http://dev.mysql.com/doc/refman/5.0/...nsitivity.html indicates all you need is a binary string type.
    Code:
    SELECT * FROM `users`
    WHERE `username` = '".$user."' COLLATE latin1_bin AND `password` = '".$pass."' COLLATE latin1_bin
    Try that.

  • Users who have thanked Fou-Lu for this post:

    tomharto (07-26-2011)

  • #6
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    That works, thanks a lot


  •  

    Posting Permissions

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