Page 1 of 1

Error by mysql when a field include an apostrophe.

PostPosted: 25. April 2010 14:21
by spino
I have an application done in php, mysql, and apache2 created in linux.
I had a transfer into the wonderful xampp ... but now I have a problem.

When a field contains an apostrophe the query aborts. This don't happens in Linux.

To explain me better, I attach an example:

INSERT INTO anagrafica (idanagrafica, tipodocumento, editore, collocazione, annoedizione, titolo, id_autore, annotazioni, file, user_agg, data_agg) values ($idanagrafica, $tipodocumento, '$editore', '$collocazione', $annoedizione, '$titolo', $autore, '$annotazioni', '$file', '$user_agg', '$data_agg');

fails if one or more fields like '$titolo' , '$collocazione', '$editore' etc. contain an apostrophe inside.

Please can some body help me?

Re: Error by mysql when a field include an apostrophe.

PostPosted: 26. April 2010 01:35
by MC10
I believe that you use the addslashes() function in PHP in order to escape the ' so that they get inputted correctly into the MySQL database. See this for more information.

Re: Error by mysql when a field include an apostrophe.

PostPosted: 26. April 2010 04:45
by Altrea
or even better the mysql_real_escape_string()-function

or even more better the mysqli-prepared-statements model :D

Re: Error by mysql when a field include an apostrophe.

PostPosted: 26. April 2010 10:39
by spino
Tank you to both for help me :D
Now I have something to think about :roll:
Bye