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

不用php-android在mysql中插入记录?

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:

 <?php
     mysql_connect("localhost","root","");
     mysql_select_db("database_name");
     $sql=mysql_query("insert into table_name values('".$_REQUEST['s_name']."')");
     $r=mysql_query($sql);
      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"));

   try{ 
       HttpClient httpclient = new DefaultHttpClient();
       HttpPost httppost = new HttpPost("http://10.124.238.51PH/get_cities_names.php");
       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 2012-08-28 09:21
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记