Error by mysql when a field include an apostrophe.

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Error by mysql when a field include an apostrophe.

Postby spino » 25. April 2010 14:21

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?
spino
 
Posts: 2
Joined: 25. April 2010 14:15

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

Postby MC10 » 26. April 2010 01:35

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.
MC10
 
Posts: 148
Joined: 20. February 2010 20:13

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

Postby Altrea » 26. April 2010 04:45

or even better the mysql_real_escape_string()-function

or even more better the mysqli-prepared-statements model :D
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

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

Postby spino » 26. April 2010 10:39

Tank you to both for help me :D
Now I have something to think about :roll:
Bye
spino
 
Posts: 2
Joined: 25. April 2010 14:15


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 31 guests