0

I need to update a field into database using Ajax and PHP.

It works fine but when there are special characters like following

اللهم اني اشكو اليك ضعف قوتي وقلة حيلتي وهواني علي الناس

The script inserts junk data into the database.

I tried using escape() of javascript to do URL encoding, it encodes the data but when I decode it using PHP it again shows junk values.

5
  • 1
    There should be no need to encode anything as long you handle it like UTF-8 data from start to finish. What's your database/database connection/app/website encoding set to? Commented Nov 18, 2010 at 7:32
  • my database is mysql, php is in charset=utf-8 since i am using ajax, the parameters i am passing need to be url supported, if I don't encode the string it just ignores the call. And when i encode the string using javascript sends the data through AJAX to a PHP processing page. but when I try to decode it to original string its not getting decoded properly. Commented Nov 18, 2010 at 7:37
  • 1
    some example for you to check - stackoverflow.com/questions/4143853/… Commented Nov 18, 2010 at 7:39
  • my database is in UTF-8 only. I can update the same field by normally Posting data from a form. But I need to do it in Ajax and when I make a call using Ajax it just sends junk data. Commented Nov 18, 2010 at 7:57
  • Original String : اللهم اني اشكو اليك ضعف قوتي وقلة حيلتي وهواني علي الناس encoded using javascript escape() method %D8%A7%D9%84%D9%84%D9%87%D9%85%20%D8%A7%D9%86%D9%8A%20%D8%A7%D8%B4%D 9%83%D9%88%20%D8%A7%D9%84%D9%8A%D9%83%20%D8%B6%D8%B9%D9%81%20%D9%82% D9%88%D8%AA%D9%8A%20%D9%88%D9%82%D9%84%D8%A9%20%D8%AD%D9%8A%D9%84%D8 %AA%D9%8A%20%D9%88%D9%87%D9%88%D8%A7%D9%86%D9%8A%20%D8%B9%D9%84%D9%8 A%20%D8%A7%D9%84%D9%86%D8%A7%D8%B3 recieved at PHP file / dencoded using php urldecode اللهم اني اشكو اليك ضع٠قوتي وقلة حي٠„تي وهواني علي الناس Commented Nov 18, 2010 at 7:58

1 Answer 1

1

You can try using encodeURIComponent instead of escape, that will give you something like this:

%D8%A7%D9%84%D9%84...

whereas escape would yield:

%u0627%u0644%u0644%u0647...

and the unicode escapes might be confusing someone.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, encodeURIComponent gives me something like this %D8%A7%D9%84%D9%84%D9%87%D9%85%20%D8%A7%D9%86%D9%8A.... but how to decode this in PHP
AFAIK urldecode (php.net/manual/en/function.urldecode.php), then see if what you get is Arabic, then try putting the Arabic in the database and see what comes out. At least then you'll know who is mangling the unicode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.