How to turn off case sensitivity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • julox
    New Member
    • Mar 2007
    • 3

    #1

    How to turn off case sensitivity

    Hello all,
    Just want to ask you how could I disable case sensitivity in php.
    I am comparing 2 strings (letters and numbers) to add to database (mysql) only non existing strings.
    code:
    if ($_GET['polozka'] !== $row3['polozka']){


    $insertSQL = "INSERT INTO sklad (polozka, druh_tovaru, dodavatel, kusy) VALUES ('$_GET[polozka]', '$_GET[druh_tovaru]', '$_GET[dodavatel]', '$_GET[kusy]')";

    $Result1 = mysql_query($in sertSQL, $SQL) or die(mysql_error ()); }

    How could I make it to test if statement without case sensitivity?... .I am fresh beginner in php, so I am looking for help from more experienced people....Thank s in advance...
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You can turn any string to lower case using the strtolower() function.
    Doing that to both the test strings will make the test case-insensitive.

    Comment

    • julox
      New Member
      • Mar 2007
      • 3

      #3
      ye yuo're right..
      but i just realized that what i need is to make select from database case insensitive.... .
      What i need is to avoid to have 2 same items in the database. So i want to make test before I write something to database if there is this item already or not(does not matter if with big or small letters)
      my code for this looks like this:
      $query3 = "SELECT * FROM sklad WHERE polozka='$_GET[polozka]'";
      $Result3= mysql_query($qu ery3,$SQL);
      $row3 = mysql_fetch_arr ay($Result3,$SQ L);

      if ($_GET['polozka']!==$row3['polozka']){

      $insertSQL = "INSERT INTO sklad (polozka, druh_tovaru, dodavatel, kusy) VALUES ('$_GET[polozka]', '$_GET[druh_tovaru]', '$_GET[dodavatel]', '$_GET[kusy]')";
      $Result1 = mysql_query($in sertSQL, $SQL) or die(mysql_error ());
      }

      How could I make this test case insensitive?Lik e I said I am fresh beginner, so I
      realize that whole code for this could be done smarter ...Thanx in advance for your advice..

      Comment

      • julox
        New Member
        • Mar 2007
        • 3

        #4
        OK I solved it (I hope its I good solution...let me know if there could be any bug)

        $query3 = "SELECT * FROM sklad WHERE polozka='$_GET[polozka]'";
        $Result3= mysql_query($qu ery3,$SQL);
        $row3 = mysql_fetch_arr ay($Result3,$SQ L);

        if ($row3==0){

        $insertSQL = "INSERT INTO sklad (polozka, druh_tovaru, dodavatel, kusy) VALUES ('$_GET[polozka]', '$_GET[druh_tovaru]', '$_GET[dodavatel]', '$_GET[kusy]')";
        $Result1 = mysql_query($in sertSQL, $SQL) or die(mysql_error ());
        else {
        ?>
        <!-- pop up warning-->

        <script type="text/JavaScript">Mes sage('Polozka <? echo $row3['polozka'] ?> already exist !');
        document.locati on.href = "index.php" ;

        </script>

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Ok, If im reading this right, you need to avoid adding the same item twice into your database?

          If so you can simply mark the column UNIQUE when you create the table (or alter it if you already have) and use the strtolower() function to de-capitalize all strings before you insert them.
          Then MySQL wont allow you to add the same text into the column twice.

          Comment

          Working...