0

I am trying to make a script, that interact with mysql database and allows to find someone by username. But the problem is that it is not comparing characters. Means in my databse, user name is "abcd", in lowercase. But when I go to

localhost/ABCD or localhost/Abcd or localhost/ABcd or any upper or lowercase, it shows me same result. I want different result with different cases. I don't know what to use. I searched a lot and found preg_match function but don't know how to use. The function I created for this match from database is,

function CheckPnP($var){
    $db = new mysqli ('localhost', 'root', '', 'database');

    if($var){
if($result = $db->query("SELECT * FROM  `view` WHERE `username` =  '$var'")){
            if($result->num_rows){
                $rows = $result->fetch_assoc();     
                $_GET['username'] = $rows['username'];
                $_GET['view'] = $rows['page'];  
                include $_SERVER['DOCUMENT_ROOT'].'/core/view.php';
                return true;
            }       
        }   
    }       
}

and my view.php page codes are

<?php
@$view = $_GET['view'];
@$username = $_GET['username'];

if($view == 'profile'){
    echo 'This is profile page.';

    }
 else if ($view == 'page'){
    echo 'This is page.';
    }
else if ($view){
    header('Location: /');
    }   
else if (empty($view)){
    echo 'this is view page123. ';
}

echo '<br>'.$username;

?>

view.php page's codes are temporary. I will change them soon but right now I need to match characters of username from database and I need exact character match.

Please help me.

1 Answers1

0

I actually just found out about this a few weeks ago:

SELECT * FROM `your_table` WHERE BINARY `your_column` = 'VaLue';
SELECT * FROM `your_table` WHERE BINARY `your_column` = 'value';
SELECT * FROM `your_table` WHERE BINARY `your_column` = 'vaLue';

This would return different results depending on your query.

I suggest you do the above instead of in PHP.

About your second question:

There are a ton of things you can do to match characters in PHP. strcmp (case sensitive), ===, ==, strcasecmp (case insenstive)

Teej
  • 12,764
  • 9
  • 72
  • 93