1

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,842
  • 3
  • 30
  • 44
Metay Jack
  • 53
  • 1
  • 11

6 Answers6

2

You can use BINARY for that.

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

That will make a case sensitive match.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 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,433
  • 7
  • 27
  • 51
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
  • 40,431
  • 11
  • 76
  • 106
0

Try like

SELECT ID
FROM Login
WHERE Username = 'angel' COLLATE utf8_bin;
GautamD31
  • 28,552
  • 10
  • 64
  • 85
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
  • 13,817
  • 5
  • 55
  • 55
0

Try like

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