1

I have a really big problem with saving data from Flash as2 to database. I tried solved it myself, read many topics on different forums but no result.

I have an Input Text field (mess_txt) in as2 project and Send button with the next code:

on(release){
   var formData = new LoadVars();
   formData.etext = mess_txt.text;
   formData.sendAndLoad("sendmail.php", formData, "POST");

   formData.onLoad = function(){
       // receive actions...
   }
}

Code in sendmail.php:

include("connect.php");
$text = $_POST['etext'];

$text = str_replace("\r", "<br/>", trim(strip_tags($text)));
$text = str_replace("\n", "", $text);
$text = str_replace("\"", "&quot;", $text);
$text = str_replace("'", "&#39;", $text);

$query = "insert into reviews (text, status) values ('".$text."', 'new')";
mysql_query($query) or die (mysql_error());

mail("mail@gmail.com", "Title!", "Message text: ".$text);

When I use latin symbols both code works well but when I input cyrillic symbols in Input Text I have an empty string in PHP code. In Input Text I use _self font and embed all glyphs. But I think that problem is in sending data because when send simple cyrillic string instead mess_txt.text I have an empty string as well.

Interesting, that when I used mb_detect_encoding($_POST['etext']) in PHP code I obtained ASCII not UTF

Please, help me!!!!


SOLVED!!!

I found how to solve this problem! May be it will be interesting for someone else...

Before sending data from as2 to php I transformed it from text to unicode codes. This is my function in as2 project:

on(release){
   var txt = getRealText(mess_txt.text);

   var formData = new LoadVars();
   formData.etext = txt;
   formData.sendAndLoad("sendmail.php", formData, "POST");

   formData.onLoad = function(){
       // receive actions...
   }

   function getRealText(str){
       var newStr = "";
       for(i=0, s=str.length; i<s; i++){
            newStr += "&#"+ord(str.charAt(i))+";";
       }
       return newStr;
   }
}

As result I sending string "&#1090;&#1077;&#1089;&#1090;" instead "тест". In PHP file I received this string:

$text = html_entity_decode($_POST['etext'], ENT_NOQUOTES, 'UTF-8');

After that I obtained normal cyrillic (or any another) text.

Have a hope that this will be useful for someone!

Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
lubart
  • 1,746
  • 3
  • 27
  • 35
  • 1
    As you've fixed the problem yourself, you should post it as an answer, rather than editing the question. Apart from anything else, you can earn reputation on the answer then, as well as the question. As a token of good-faith, if you @-tag me in another comment here, I'll come up-vote your answer, given it appears to be well-worded. – Owen Blacker May 03 '12 at 12:15
  • Hi, I tried to add answer instead of comment in this topic, but I have not enough reputation yet. That is why I organized answer in comment. – lubart May 03 '12 at 13:18
  • Ah, I see. Sorry, that sucks :o( I've up-voted some of your questions, which might help. You should also go and give a green tick to any answers you found helpful, like [this one](http://stackoverflow.com/a/9970195/205245), which will also earn you reputation. – Owen Blacker May 03 '12 at 13:47

0 Answers0