There is a code, it receives the text by post-request:

$msg = isset($_POST['usersmsg']) ? $_POST['usersmsg'] : false; if ($msg) { $result = mysql_query("INSERT INTO msgs (did,sid,text) VALUES('$did','$sid','$msg')",$db); 

All characters are correctly added, but "+" is not added, instead of it a space is written in the base. Base coding utf8_unicode_ci
Example:

Example

As I understand the problem with the encoding, the meta tags are worth

 <meta charset="UTF-8"> 

When connecting to the database:

 mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET SESSION collation_connection = 'utf8_general_ci'"); 

Please tell me what the problem is, in which direction should I google?

  • By the way, it’s absolutely impossible to substitute $msg in SQL-code in this way, because you get a SQL injection: some hacker will send a message '); DELETE from msgs; -- '); DELETE from msgs; -- '); DELETE from msgs; -- - and your base crying. Read Google about screening SQL, about mysqli (PHP's mysql module has long been outdated), about PDO and about placeholders in order to make the code safer. - andreymal

2 answers 2

Before sending data to the server, it is necessary to encode it with the help of JS functions encodeURIComponent ()

More details here.

  • And how do these millions of forms around the world work without any JavaScript in principle? - PinkTux
  • @PinkTux millions of forms are processed by the browser itself with shielding as it should be, and the author of the question seems to do everything through JavaScript and mow down - andreymal
  • How exactly does the author of the question - we do not know. - PinkTux
  • @PinkTux however, judging by the fact that this answer is marked as the best, - does exactly that :) - andreymal
  • Thanks to everyone for the answers, yes I do it through JavaScript. Because the data does not come from textarea, but from an editable div. Perhaps someone else knows how to transfer line breaks to the database? ) - Yarik

Neither MySQL nor PHP have anything to do with this. The plus symbol encodes a space in an HTTP request. Passing the string testing+example to POST or GET you actually pass the string testing example . More basic knowledge - on request "url encoding" in google.