0

I am posting Comments in hindi to another page, where i insert to db, but the comments is getting saved as junk in mysql.

--PHP

<form method='post' action='post.php'>
    <textarea name='comments'></textarea>
</form>

--post.php

$comment =$_POST["comments"];  
$query = "INSERT INTO comments SET comment='".mysql_escape_string($comment)."' ";
mysql_query($query) or die(mysql_error());

In DB the text gets inserted as junk characters the database is of correct type as i have inserted the html notation on हिंदी { hindi characters to be saved} , and display works with correct META type,

but DB entry is like à╧√à╧¿à╧?à╧▌à╛?

i tried an insert query in the same file and it worked, but posting to some other file creates the problem, is it someting to do with posted data ?

i cannot use same file for insertion as other forms are there in the same page, which are handled.

Naveen Kumar
  • 4,543
  • 1
  • 18
  • 36
  • This usually happens as a result of not taking character encodings into account, especially if you're using Latin-1 as your default encoding or if different parts of the system are using different encodings. Make sure your database, PHP scripts, form submissions, etc are in UTF8 – GordonM Nov 22 '13 at 11:18
  • my db is latin1 , meta type is iso-8859-1, when i insert in the same page it saves properly , but in posted page, it is not working – Naveen Kumar Nov 22 '13 at 11:30
  • Have you looked at this https://stackoverflow.com/questions/14273549/devnagri-hindi-font-not-getting-stored-in-mysql?noredirect=1&lq=1 – Yogi Devendra Oct 13 '17 at 11:52

1 Answers1

0

You should try setting your "file encoding" to UTF-8 and so does your database encoding.

Most people forget that a file also has an encoding type. Especially on Windows this will bring you trouble.

Benjamin de Bos
  • 4,334
  • 4
  • 20
  • 30