I am sending a JSONArray to a server where my script decodes it and uses the data within to update a MYSql database. The problem at the moment is that everything works as it should do until the script encounters a field containing an apostrophe which I understand is used by php as an escape character.
How do I avoid this while still preserving the apostrophe? Do I add something at the Android end and then remove it server side or can I ignore it at the server side while still preserving it?
Any help is appreciated.
Reading between the lines, your problem is not that PHP treats the apostrophe as an escape (it doesn’t), but that you are not sanitising your database input.
In a MySQL query, an apostrophe has a special meaning (string encapsulator) and the presence of an unescaped apostrophe breaks your SQL syntax.
I don’t know which database driver you are using, but you either need one of these:
mysql_real_escape_stringmysqli_real_escape_string…or better, use prepared statements.