View Full Version : AS3 to PHP to mySQL - problem with ' this little thing
ruiganga
September 16th, 2009, 07:10 PM
Hi
I have a textfield where I type whatever I want
when I press a button it do the following:
- add the content of the textfield to a String, this string is a mySQL generated dinamically.
- send this string to a php that executes this mySQL query string;
everythings works fine. the only problem I have is when I need write a word with ' like dog's or la l'orona. How can I fiz this?
Thanks
_kp
September 16th, 2009, 07:31 PM
I think ' needs to be escaped to \' to not mess up the SQL query string.
There are another two characters you should escape: http://codecodex.com/wiki/Escape_sequences_and_escape_characters#SQL
ruiganga
September 16th, 2009, 07:51 PM
HI
Thanks for the tip. my problem is that this is for a kind of control panel. One of the textfields is to past the Googlemaps URL that sometimes uses ' , I don't want to search each URL to check if it as the ' or not.
I am thinking about a solution. This my variable that catch info from the textfields and transform it in a mySQL query:
var sqlQuery:String = "INSERT INTO `postos` ( `id` , `nome` , `contactos` , `morada` , `codigo` , `link` , `localidade` , `distrito` ) VALUES (NULL , '"+nomeText.text+"', '"+contactosText.text+"', '"+moradaText.text+"', '"+codigoText.text+"', '"+linkText.text+"', '"+localidadeText.text+"', '"+distritoText.text+"')";
what I need to do is check if the textfield have ' and if it have escape it. but I don't know how I do it!!!
any idea?
Thanks
_kp
September 16th, 2009, 08:12 PM
Replace with regular expressions :)
var regexp:RegExp = /'/g;
string = string.replace(regexp, "\'");
ruiganga
September 16th, 2009, 10:11 PM
this didn't solve the problem
even with
INSERT INTO `postos` ( `id` , `nome` , `contactos` , `morada` , `codigo` , `link` , `localidade` , `distrito` ) VALUES (NULL , 'teste', 'teste', 'teste', 'teste', 'testehttp://d/'alia', 'teste', 'teste')
it is deteting the open ' that not have another to close
any idea on solving this?
Thanks
_kp
September 17th, 2009, 06:54 AM
It should be 'testehttp://d\'alia' to work, not 'testehttp://d/'alia'.
I made the same mistake when posting the code, I used / instead of \ and edited my post without testing it.
Flash itself needs to escape the character \ in strings, so the replace string has to be "\\'"
var s:String = "testehttp://d'alia";
var regexp:RegExp = /'/g;
s = s.replace(regexp, "\\'");
trace(s); // testehttp://d\'alia
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.