duanfenhui5511 2014-03-24 17:13
浏览 21

too long

Im trying to add values into my Mysql database with a Android Application here is my Php file :

<?php 

    $connection = mysql_connect("mywebhost.example", "user", "password")ordie(mysql_error());
    $selection = mysql_select_db("name_of_database", $connection)or die(mysql_error());

    $name = $_POST['name'];
    $points = $_POST['points'];

    $insert = "INSERT INTO my_table('name','points') VALUES('$name','$points')";
    $run = mysql_query($insert)or die(mysql_error());

?>

And here my Android Code :

public void test_button (View view)
{
    new netsd().execute();

}


class netsd extends AsyncTask<String,String,String> 
{

     @Override
     protected void onPreExecute() {
         super.onPreExecute();
         pDialog = new ProgressDialog(MainActivity.this);
         pDialog.setMessage("Loading . Please wait...");
         pDialog.setIndeterminate(false);
         pDialog.setCancelable(false);
         pDialog.show(); 
     }

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("country", country));
        nameValuePairs.add(new BasicNameValuePair("points", Integer.toString(points)));

        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("http://heremyexampel.com/android_connect.php");
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }


    protected void onPostExecute(String file_url) {


        pDialog.cancel();
    }


}

I dont get any problems in Eclipse but there is no values in my Mysql.So hes not adding them... I tried it with this AsyncTask but really dont get it well... For what is this

  <String,String,String>

Is it because of that ? Thank you ! (Of course Passwort server link etc are example)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料