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 ?

8
  • You've prepared the query! That's an important step done! The next step is to execute it! Commented Sep 22, 2017 at 7:14
  • LIKE is case-insensitive use = instead. Commented Sep 22, 2017 at 7:17
  • 2
    Tried to check this link. It might help you stackoverflow.com/questions/24142512/… Commented Sep 22, 2017 at 7:20
  • 1
    You mean the BINARY in front of password ? gonna check that now. Commented Sep 22, 2017 at 7:21
  • 1
    @SherwinObciana thats the solution i was looking for - BINARY in front of the password / username. Commented Sep 22, 2017 at 7:23

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

0

just use = instead of LIKE

LIKE is case-insensitive

1 Comment

Yes, i didn't know about the BINARY also.
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();

4 Comments

Why negative vote? Please provide proper explanation
@ downvoter, whats the wrong in Pankaj Makwana solution ?
The OP is most likely executing the query, the OP asked I want to check if the letters are upper or lowercase
i need to check for upper and lowercase - sorry for my bad english.
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

2 Comments

these are just other solutions.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.