-2

I need to send text from Android to database on server and I'm faced with some question marks for non-English characters.

PHP code:

<?php

header('Content-Type: text/html; charset=utf-8'); 
$con=mysql_connect("xxxxx","xxxxx","123456");
mysql_select_db("xxxxx",$con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
$user=$_POST['username','utf8'];
$matn=$_POST['matn','utf8'];
$status=$_POST['status','utf8'];
if($user!=""){
    $sqlQ="insert into content(username,matn,status) VALUES('$user','$matn','$status')";
    $result=mysql_Query($sqlQ);
    if($result){
        print "ok";
    }
    else
    {
        print "no";
    }
}else{
    print "-";
}
mysql_close($con);

?>
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Amix
  • 17
  • 5
  • 1
    The POST-array doesn't have encoding as a second argument in the index – Qirel Aug 05 '17 at 17:57
  • 5
    Possible duplicate of [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Qirel Aug 05 '17 at 17:57
  • yes those utf8 are extra and I delete those but not works – Amix Aug 05 '17 at 18:01
  • Set the charset on the connection (`mysql_set_charset()`) too. Any data in the db that's already of the wrong charset won't be fixed though – Qirel Aug 05 '17 at 18:24
  • I set this but not works , I do not know what should I do – Amix Aug 05 '17 at 18:55
  • Like it says in the dupe, you need to ensure everything is in utf8. [This question](https://stackoverflow.com/questions/31897407/mysql-and-php-utf-8-with-cyrillic-characters/31899827#31899827) has a little checklist for PHP you can follow, but you need to set it in Java too – Qirel Aug 05 '17 at 20:46

1 Answers1

0

Do not use the deprecated mysql_* interface, use mysqli_* or PDO.

What is that second dimension in the array $_POST?

The question marks imply that the data was not stored correctly; see http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored

Rick James
  • 135,179
  • 13
  • 127
  • 222