Hi Guys,

I was wondering if you might be able to shed some light on a problem that I'm having.

I have a script that allows a user to add a new product category to the database. Before this is done the following element checks whether the category already exists;

$sqlcheckcat="SELECT category FROM categories WHERE category='$name'";
$catnum = mysql_num_rows($sqlcheckcat);
if ($catnum > 0) {$catexist="1"; require "add_col_cat.php";}

else {	

$sql="INSERT INTO categories (category) VALUES('$name')";

The problem being that if the query is case sensitive. So if the category 'Computers' already exists and I try to add 'computers' it won't pick it up. Is there a way to make my query non case sensitive?

Thanks in advance for any advice,

    Change the collation on the category column to a case insensitive character set (e.g. one that ends in "_ci", such as "utf8_general_ci"). See this page in the MySQL manual for more information about case sensitivity.

      Hey Brad,

      Thanks again, your advice is invaluable as always. I didn't know I could set individual fields to case insensitive.

      My actual problem turned out to be that I was trying to run the sql query without prefacing it with mysql_query()

      Thanks,

        Write a Reply...