Word problem using quotes when doing INSERT SQL

Asked

Viewed 142 times

0

I’m having problems when I will perform the Insert in mysql when I have a word that contains ex Quotes (box d'agua) in any input form, when I have the mysql error saved. I have already changed the charset and I did not succeed! The script works perfectly writes all the data and such. But if any word with quotes from the error appears! How do you fix it?

I am using PHP and MYSQL

  • Welcome André Luis Diego, how about the question "Has anyone been there?" the short answer is "YES"

  • 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

  • Leo vlw for the tip I managed to solve thanks friend to you and Junio

  • 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

2 answers

0


Hello friend do not know which language is using for your script but direct on sgbd can realize these two forms.

INSERT INTO professor
VALUES ('caixa d\'agua');


INSERT INTO professor
VALUES ("caixa d'agua");
  • It worked out man, vlw by tip saved the day obg

0

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

Browser other questions tagged

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