PHP的Android脚本,使用php脚本和来自android的httppost将数据添加到在线数据库

在我的应用程序中,我为用户完成了特定的表单,并且希望将这些数据存储在我的在线数据库中。

这是我在java中的代码:

public void send_data_to_DB(){

String result = "";

InputStream is = null;

StringBuilder sb=null;

ArrayList nameValuePairs = new ArrayList();//() before

nameValuePairs.add(new BasicNameValuePair("table", table));

nameValuePairs.add(new BasicNameValuePair("code", Integer.toString(code)));

nameValuePairs.add(new BasicNameValuePair("name", name));

nameValuePairs.add(new BasicNameValuePair("email", email));

try{

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://myurl.php");

HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs);

httppost.addHeader(entity.getContentType());

httppost.setEntity(entity);

HttpResponse response = httpclient.execute(httppost);

//HttpEntity entity = response.getEntity();

//is = entity.getContent();

}catch(Exception e){

Log.e("log_tag", "Error in http connection "+e.toString());

}

}这是我的PHP脚本:

mysql_connect("dserver","User","Code");

mysql_select_db("DB_Name");

$table.=$_POST['table'];

$code.=$_POST['code'];

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

$email.=$_POST['email'];

$q=mysql_query(" INSERT INTO {$table} (code,name,email) VALUES ({$code},{$name},{$email}) ")or die(mysql_error());

mysql_close();

?>我认为它必须是我的PHP和我分配或使用变量的方式,但我不是很有经验的PHP。你可以帮我吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值