0

need to record all information in lower case in the database. How to do this with mysql?

mysql_query("INSERT INTO event (codigo_stm,playlist,startdate,starttime,repeatc,priority,loopatend,enddate,shuffle) VALUES ('".$dados_stm["codigo"]."','".$_POST["playlist"]."','".$_POST["data"]."".$data2."' ,'".$_POST["hora"].":".$_POST["minuto"].":00' ,'".$_POST["repeatc"]."' ,'1','1','".$_POST["data_fim"]."','".$_POST["shuffle"]."')");

What PHP or database function do I use to insert lowercase into the database?

jww
  • 97,681
  • 90
  • 411
  • 885
Cassiano José
  • 139
  • 1
  • 6

5 Answers5

3

Declare a variable before inserting the value to the DB. In here you can do some operations like:

$data = strtolower($_POST['data']);

Plus use some sanitation methods. What are the best PHP input sanitizing functions?

Or prepare statements. http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php You should never trust the user input!.

You can do it with MySQL using the function LOWER. http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_lower

Community
  • 1
  • 1
Ed Capetti
  • 339
  • 2
  • 10
2

Before passing your values to mysql lower your string by function given below.

$xyz=strtolower($str);

Abhishek kadadi
  • 120
  • 2
  • 11
2

Just use the php strtolower function.

$str "HelLo WoRlD";
$str = strtolower($str);
echo $str; //echos "hello world"

PHP manual strtolower function

jpycoder
  • 76
  • 5
  • 1
    And please, please, please escape your input so you don't get a SQL injection... so `mysql_real_escape_string(strtolower($_POST["playlist"]))` for each one... – degenerate Feb 09 '14 at 04:55
  • 1
    I think everyone needs to know the tale of [Bobby Tables](http://bobby-tables.com/) – Mat Carlson Feb 09 '14 at 05:00
1

You can use LOWER in mysql

INSERT INTO your_table (name, language)
VALUES ( "Some Name", LOWER( "SOME VALUE" ) );

Another option is use strtolower in php

Side Note: Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
Emilio Gort
  • 3,475
  • 3
  • 29
  • 44
1

In PHP - Use strtolower for any string you want in lowercase only.

In MySQL - Use LOWER, although doing it in PHP makes much more sense.

A side note - Make sure you sanitize your inputs and name your child Robert'); DROP TABLE students;--.

Mat Carlson
  • 543
  • 3
  • 12