So I am trying to do a fairly simple task, compare a string with a mysql table row/entry using eg.
SELECT * FROM table_name WHERE $string = table_column.
My issue is, is that it is searching and remaining case sensitive.
The string: "A Long String"
The database entry "A Long String"
My table is collated: latin1_swedish_ci which should be searching in case insensitive (like the rest of my queries), I believe since the strings contain whitespace it could be the issue, it is only looking at the first character's capitalisation.
I have tried using 'Upper' and 'lower' comparisons in my queries as well as using 'LIKE' I have also tried removing whitespace using REPLACE but I am probably doing it wrong, not entirely sure. But it never seems to find the correct entry unless I type it as it is in the database.
Any advice would be cool!
$result = mysqli_query($db, "SELECT * FROM character_information WHERE
(reference LIKE '".$origin_name."' AND char_name LIKE '".$char_name."')
OR
(lower(reference) LIKE '".$origin_name."' AND lower(char_name) LIKE '".$char_name."')
OR
(upper(reference) LIKE '".$origin_name."' AND upper(char_name) LIKE '".$char_name."')
AND
(char_gender = '".$char_gender."')");
Another try?
$result = mysqli_query($db, "SELECT * FROM character_information WHERE
reference = '".$origin_name."' AND char_name = '".$char_name."' AND char_gender = '".$char_gender."'");
I know this one is completely wrong, not meant to use REPLACE in this kind of way im assuming, should be used in UPDATE or INSERT? Anyway you can see what I am trying to do by removing the whitespace from everything.
$origin_name = str_replace(' ', '', $origin_name);
$char_name = str_replace(' ', '', $char_name);
$result = mysqli_query($db, "SELECT * FROM character_information WHERE
( (REPLACE(reference, ' ', '' )) LIKE '".$origin_name."' AND (REPLACE(char_name, ' ', '' )) LIKE '".$char_name."%')
AND
(char_gender = '".$char_gender."')");
SELECT * FROM character_information WHERE char_gender = 'male'