doufu2396 2012-08-20 06:07
浏览 24
已采纳

使用PHP从Android发送Gujarati文本到MySQL

I am developing a sample app which has two textboxes that takes input from users. Now I have created a Gujarati keyboard using buttons so that user enters data in Gujarati language. When user presses Save button the data should be stored in MySQL. This is my complete code:

public void saveMy(View v)
{
    name=e1.getText().toString();
    no=e2.getText().toString();
    try {
            httpclient = new DefaultHttpClient();
            httppost = new HttpPost("http://10.0.2.2/GujaratiApp/myPHP.php");


            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("Name",name));
            postParameters.add(new BasicNameValuePair("No",no));
            httppost.setEntity(new UrlEncodedFormEntity(postParameters));

            HttpResponse response = httpclient.execute(httppost);
            Log.i("postData", response.getStatusLine().toString());
        }
    catch(Exception ex)
    {
        Log.e("log_tag", "Error:  "+ex.toString());
    }   


}

And my PHP file is:

<?php 

  mysql_connect("localhost","root","") or die(mysql_error());

  mysql_select_db("newDB");

  $name =   $_POST['Name'];

  $no = $_POST['No'] ;

  print("Name is:   ".$name."             And No is:".$no);

  $query_add="INSERT INTO  myData (`name` ,`no` ) VALUES ('$name','$no')";

  $query_exec=mysql_query($query_add) or die(mysql_error()); 

  mysql_close();

?>

Query used to create database is:

CREATE TABLE myData (name VARCHAR(20) NOT NULL,no VARCHAR(5) NOT NULL) ENGINE=INNODB CHARACTER SET= utf-8;

My data gets enter when I press Save button but in MySql i get ??? instead of Gujarati text.

when I enter English data then it works properly..

  • 写回答

2条回答 默认 最新

  • dongsheng8158 2013-02-14 05:56
    关注

    Just a little change in your code. Try this.

    httppost.setEntity(new UrlEncodedFormEntity(postParameters,HTTP.UTF_8));
    

    Hope it helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧