1

at the moment, i check the username and passwort of a HTML form like this on my database:

$exc = $dbh->prepare("SELECT id, cid, fullname FROM user WHERE username LIKE :username AND password LIKE :password");

I need to check both CASE SENSITIVE when executing the query.

Database data:

username: louis
password: goal43

Form data:

username: LOUIS
password: GOAL43

returns true - how do i fix this ?

4 Answers4

2
$exc = $dbh->prepare("SELECT id, cid, fullname FROM user WHERE BINARY username LIKE :username AND BINARY password LIKE :password");

I hope it helps you. The link I've given to you

Sherwin Obciana
  • 319
  • 1
  • 11
0

You have written query in prepare. Next step to assign parameters to :username and :password parameter you can do the by bindParam(). Which is given below.

$stmt = $dbh->prepare("SELECT id, cid, fullname FROM user WHERE username = :username AND password = :password");
$stmt->bindParam(':username ', $username);
$stmt->bindParam(':password', $password);
$stmt->execute();
Puja
  • 451
  • 2
  • 5
  • 20
Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47
0

just use = instead of LIKE

LIKE is case-insensitive

Michael M.
  • 189
  • 1
  • 7
0

This question is already asked and contains answer , you can see this link there are very good answers for your query Compare string with case sensitive data

Muhammad Aadil Banaras
  • 1,134
  • 1
  • 11
  • 21
  • these are just other solutions. –  Sep 22 '17 at 08:12
  • yes but you can use them to solve yours query , you can use like as well as = , but if you use = then query must be like this Select * from a_table where attribute = 'k' COLLATE Latin1_General_CS_AS this will match if cases of characters are matched – Muhammad Aadil Banaras Sep 22 '17 at 09:53