我的Java功能如何將java中的值添加到php中?
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());
}
}
我的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();
?>
當我執行它,那我走了數據庫那裏看看。
它被添加,但爲空值。
所以,我的問題是如何傳遞的EditText上獲得的Java到PHP
得到它,我的錯字錯誤 – newonandroid 2011-05-19 14:20:37