this code doesnt check captol letters. how can i do this.
for examle is i have "cat" in table "user". than if i set $username_p to Cat. and it will work fine.
but i dont want to work bc Cat != cat.

$sql = mysql_query("SELECT id FROM user WHERE username='$username_p' AND password='$password_p' LIMIT 1");
full code....
    $sql = mysql_query("SELECT id FROM user WHERE username='$username_p' AND password='$password_p' LIMIT 1");

                //make sure person exists in database---
                $existCount = mysql_num_rows($sql); //count the row num
                if($existCount == 1) //make sure name is only one in database
                {
                    while($row = mysql_fetch_array($sql))
                    {
                        $id = $row["id"];
                    }
                    //create session variables
                    //so site can remember who loged in
                    $_SESSION["id"] = $id;
                    $_SESSION["username"] = $username_p;
                    header("location: index.php");  
                }
                else
                {
                    $log_error .= 'Error - Incorrect username or password!';
                }

Recommended Answers

Use the BINARY key word:

"SELECT id FROM user WHERE BINARY username='$username_p' AND password='$password_p' LIMIT 1"

I'm assuming the password is hashed so you don't need this case sensitivity on that.

Jump to Post

All 4 Replies

You'll need to change your collation to something that is case sensitive. Case insensitive is usually default.

by collation you mean sql query?

Member Avatar

Use the BINARY key word:

"SELECT id FROM user WHERE BINARY username='$username_p' AND password='$password_p' LIMIT 1"

I'm assuming the password is hashed so you don't need this case sensitivity on that.

perfect! binary works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.