Insert a data into the database containing some types of characters, may cause error.
PHP-Mysql: Inserting single quotes, double quotes in the database
Characters that may cause insertion problems: apostrophe (')
, quotation marks (")
and backslash (\)
.
Example of text to be saved:
Olá Sra. Caixa d'agua, seja bem-vinda ao ‘stackoverflow’
Imagine that you typed the above text in a field of your form and now you want to save it to the database. Doing the Insert directly from this text will give error.
To solve this problem you will need the addslashes function();
$texto = addslashes($_POST['texto']);
INSERT INTO tabela (texto) VALUES ('$texto');
Another solution:
$texto = filter_var($_POST['texto'], FILTER_SANITIZE_MAGIC_QUOTES);
Sources:
FILTER_SANITIZE_MAGIC_QUOTES
addslashes
Welcome André Luis Diego, how about the question "Has anyone been there?" the short answer is "YES"
– user60252
If the question was, "How do you fix this?" the answer would be "must escape quotation marks" see as in https://www.php.net/manual/en/function.addslashes.php
– user60252
Leo vlw for the tip I managed to solve thanks friend to you and Junio
– André Luis Derigo
I advise you to take a look at https://answall.com/questions/3864/como-prevenir-inje%C3%A7%C3%A3o-de-c%C3%B3digo-sql-no-meu-c%C3%B3digo-php
– Benilson