2012-08-28 08:21
采纳率: 100%
浏览 41


I can get data from MySql with use of php using android successfully. But i m getting some problem with inserting record in mysql table using php-android.

This is my .php file:

     $sql=mysql_query("insert into table_name values('".$_REQUEST['s_name']."')");
      if(!$r)echo "Error in query: ".mysql_error();mysql_close();

This is my android activity's onCreate method's content.

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("s_name","StackOver"));

       HttpClient httpclient = new DefaultHttpClient();
       HttpPost httppost = new HttpPost("");
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
       HttpResponse response = httpclient.execute(httppost);
       HttpEntity entity = response.getEntity();
       is = entity.getContent();

     }catch(Exception e){
          Log.v("log_tag", "Error in http connection "+e);

Here i want to pass BasicNameValuePair("s_name","StackOver")) s_name to .php but it can't be possibel. please give me some idea or links of tutorials. I have search in ner so much but i can't find proper tutorial for this. Thank you in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donvo24600
    donvo24600 2012-08-28 09:21

    Here is the tutorial for saving data and passing data. Watch it, Learn from it and then create.

    点赞 评论