Accented words are not sent to the database - PHP

Asked

Viewed 147 times

0

I made a form that sends data from a php page to a database and only the data without accentuation are being sent, if I put an accent, none of that field arrives in the database, not even something blank.

From now on I appreciate any help

Excerpt from the code:

<textarea cols=\'20\' rows=\'10\' name=\'text\'></textarea>
<input type="submit" value="Enviar" name="enviar"> 

if(isset($_POST['enviar'])){

$teste2 = $_POST['text'];

mysql_query("INSERT INTO `testes`(`texto`) VALUES ('".$teste2."');
  • Good on the accents solved colcoando a utf-8 enconde before the $POST, but now characters like /, *. + are not sent.

  • Can you post your real code? This code you put in shouldn’t even run, there are syntax errors.

2 answers

1


Certain symbols are not accepted as they can be used to enter the database through MYSQL Injection.

One way to do it is to use htmlentities and htmlspecialchars which will replace these symbols with the equivalent of html, i.e.:

$texto = htmlspecialchars(htmlentities($_POST['text']));

0

There are countless situations that can cause this to occur

  • The way you generated your table "unicode_utf8" ??
  • How you’re handling your strings?
  • Make sure you are using utf8_encode and utf8_decode correctly.
  • See if you’re using filter_var() correctly.
  • recommend you also use PDO to manipulate data is safer.

I don’t know if the bars were nescessarias anymore you can do this way without ' \ '

<textarea cols='20' rows='10' name='text'></textarea> <input type="submit" value="Enviar" name="enviar">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.