我正在處理將數據發送到服務器的程序。服務器正在接收我的數據,但只有最後一點。這是我的Android代碼:HTTPPOST Android到服務器
ArrayList<NameValuePair> j2 = new ArrayList<NameValuePair>();
j2.add("drink_name", "rootbeer")
j2.add("drink_name", "pepsi")
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("kubie.dyndns-home.com/R2Bar2/getingredients.php");
httppost.setEntity(new UrlEncodedFormEntity(j2));
HttpResponse response = httpclient.execute(httppost);
responseText = EntityUtils.toString(response.getEntity());
但它只是將最後一項(百事可樂)添加到數據庫。 這裏是我的PHP:
<?php
$handle = mysql_connect('localhost','root','xxxx');
if($handle==false)
{
die('No database connection');
}
$result = mysql_query("TRUNCATE TABLE 'available_ingredients'");
$db=mysql_select_db('r2bar2');
$query='INSERT INTO available_ingredients (drink_name) VALUES ("'.$_POST["drink_name"].'")';
$result=mysql_query($query);
?>
'ArrayList'它叫做Name - > Value pair not Name - > Value * s * pair。一個名字,一個價值。 –
hakre
2012-03-17 00:33:32