PHP Charset UTF8mb4 ,special characters are not saved into phpmyadmin when copied

602 views Asked by At

I'm having a weird problem ,not sure what the title should be and I searched before posting this ,the collation of my database is set to utf8mb4_general_ci
and so is the column, yet when I type into the text field of that column the php code saves it just fine,how ever when this special text is copied from somewhere the column stays empty ! I already have this set in my code

 $this->connection = new mysqli(HOST, USER, PASS, DB);
 $this->connection->set_charset('utf8mb4');
1

There are 1 answers

5
Afzaal On

You should use the following function before inserting it into database ,in which input_data is the data which you want to store in database . And the problem is database dont allow special character , and mostly these character are use for SQL injection , so this function do the cleaning stuff by escaping ,so the data is safe to save.

$mysqli->real_escape_string($input_data);

follow this link for documentation mysqli::real_escape_string