My website http://www.locuciones-baratas.com/ There are many textarea where user can input text. But when user input text with special character like
1.000 millones de pesetas" |#~@¬#~€¬€~¬'''¡¡!"!! "Yo he ahorrado al PP más de 1.000 millones de pesetas", ha asegurado Correa, explicando que esa cifra se corresponde con el
then record won't insert into mysql database
I tried ut8 general ci as character set.
Set meta utf8 in html
$textarea = mb_convert_encoding($_POST['textarea'], 'ISO-8859-1','utf-8');
$insert_array = array('textarea'=>$textarea);
$sql = build_sql_insert('order',$insert_array);
mysqli_query($conn,$sql) ;
function build_sql_insert($table, $data) {
$key = array_keys($data);
$val = array_values($data);
$sql = "INSERT INTO `$table` (" . implode(', ', $key) . ") " . "VALUES ('" . implode("', '", $val) . "')";
return($sql);
}
I think problem may be php dont allow special character to further proceed, data may be don't reach to mysql.
Please advice how to insert record with such text
maybe you need to escape strings.
Try adding mysqli_real_escape_string.
function build_sql_insert($table, $data, $conn) {
$key = array_keys($data);
$val = array_values($data);
//Mysql real escape string use a string value. this hack will work only
//for a single value passed. please read the comment below.
$val[0] = mysqli_real_escape_string($conn, $val[0]);
$sql = "INSERT INTO `$table` (" . implode(', ', $key) . ") " . "VALUES ('" . implode("', '", $val) . "')";
return($sql);
}
More information in php manual here
After the connection creation ($conn = .....) try to add this line:
mysqli_set_charset($conn, "utf8");