如何将java中的值添加到php中?
16lz
2021-01-22
my java function
我的java函数
private void adddataintophp(String title, String date, String time, String channel){
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//http post
try{
nameValuePairs.add(new BasicNameValuePair("Title", title));
nameValuePairs.add(new BasicNameValuePair("Date", date));
nameValuePairs.add(new BasicNameValuePair("Time", time));
nameValuePairs.add(new BasicNameValuePair("Channel", channel));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/insertprogram.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
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());
}
}
my php code
我的PHP代码
<?php
$title = $_POST['Title'];
$date = $_POST['Date'];
$time = $_POST['Time'];
$channel = $_POST['Channel'];
mysql_connect("localhost","root","");
mysql_select_db("imammuda");
$sql=mysql_query("insert into Program (ID, Title, Date, Time, Channel) values ('NULL', '$title', '$date', '$time', '$channel')");
mysql_close();
?>
when i execute it, then i go database there and see.
当我执行它,然后我去那里的数据库,看看。
It was added but with null value.
它被添加但具有空值。
So, my question is how to pass the value that get by edittext in java into php
所以,我的问题是如何将java中的edittext获取的值传递给php
2 个解决方案
#1
0
You're doing a POST request from within Java, but read the GET request inside your PHP code. When posting your data, it won't show up in the URL, where the data should be according to the GET verb.
您正在从Java中执行POST请求,但是在PHP代码中读取GET请求。发布数据时,它不会显示在URL中,其中数据应根据GET动词。
更多相关文章
- 纯真ip数据库查询的php实现(补充分组查询)
- 添加到数据库后,保持在同一页面而不刷新它
- 在Web Page中包含PHP代码
- PHP 导出 万级别数据 时间测试
- 数据库是存储我的Web应用程序数据的最佳选择吗?
- php执行数据库查询返回json格式数据
- PHP更新基于其他表的表数据
- 解决PHP导出大量数据时设置超链接的问题
- 如何用jQuery AJAX调用发送所有当前的post数据