0

I want to select the match exact word from table, but i got a problem that

if row like : Angel and i did select * from table where row = "angel" it success and first

letter is small and in db its capital,

$r = mysql_fetch_row(mysql_query("SELECT ID 
                                  FROM Login
                                  WHERE Username = 'angel'
                                    And Password = 'zxc'"));
if($r[0])
    die("success");
else
    die("failed");

In mysql Table
Username : varchar(50) : Angel
Password varchar(50) : zxc

results should be falied

because its Angel not angel

so any solution for it

Ed Chapel
  • 6,802
  • 3
  • 28
  • 43
Metay Jack
  • 43
  • 1
  • 11

6 Answers6

1

You can use BINARY for that.

SELECT *  FROM `table` WHERE BINARY `row` = 'angel'

That will make a case sensitive match.

Hanky Panky
  • 45,969
  • 8
  • 69
  • 95
1

Yes this is due to the collation of your table field. you should set it to a case sensitive collation usually suffixed with cs like latin1_swedish_cs

DevZer0
  • 13,316
  • 6
  • 25
  • 50
0

Try this,

$r = mysql_fetch_row(mysql_query("SELECT ID FROM Login WHERE  
            Password = 'zxc' AND Username collate latin1_general_cs = 'angel'"));

Read Case Sensitive Database Query and MySQL case sensitive query

Community
  • 1
  • 1
Rohan Kumar
  • 39,838
  • 11
  • 73
  • 103
0

Try like

SELECT ID
FROM Login
WHERE Username = 'angel' COLLATE utf8_bin;
Gautam3164
  • 28,027
  • 10
  • 58
  • 83
0
mysql_query("
    ALTER TABLE `Login`
    CHANGE `Username` `Username` VARCHAR(250) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL
");    

$r = mysql_fetch_row(mysql_query("SELECT ID FROM Login WHERE  Username = 'angel' And Password = 'zxc'"));
if($r[0])
    die("success");
else
    die("failed");

Now it will work.

Alexander Yancharuk
  • 12,892
  • 5
  • 49
  • 54
0

Try like

SELECT ID
FROM Login
WHERE upper(Username) = upper('angel')
esmoreno
  • 658
  • 5
  • 12