gpt4 book ai didi

php - 将数据数组从 android 传递到 php 文件不会进入数据库

转载 作者:行者123 更新时间:2023-11-29 14:01:49 24 4
gpt4 key购买 nike

我想使用名称值对将 String (itemname) 数组传递到 php 文件 (PlaceOrder.php)。当我点击 PlaceOrder button 时,它会在数据库中传递 null 值。 Android 代码或 Php 代码是否有问题?我的 Android 代码如下

public void onClick(View v) {
// TODO Auto-generated method stub
try
{

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/demo/PlaceOrder.php");
Log.e("log_tag", "connection success ");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
for (int i=0;i<1;i++)
{
nameValuePairs.add(new BasicNameValuePair("ItemName[]", String.valueOf

(resultArrItemname[i])));

}
Log.e("log_tag", "Name value pair success ");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("log_tag", "response sucess ");
HttpEntity entity = response.getEntity();
is = entity.getContent();
showDialog("Order Placed Successfully");

}

catch(Exception e)
{
Log.e("log_tag", "Error in http connection"+e.toString());
}
}

我的 PHP 代码如下

<?php

$itemname[]=$_REQUEST['ItemName[]'];

mysql_connect("localhost","root","aaaaaa") or die(mysql_error());
mysql_select_db("demo") or die(mysql_error());

foreach($itemname as $key)
{
$sql=mysql_query("Insert into tblorder(itemname) values('$key')");
while($row=mysql_fetch_array($sql))
$output[]=$row;
print(json_encode($output));
}
mysql_close();
?>

最佳答案

尝试改变

$itemname[]=$_REQUEST['ItemName[]']; 

$itemname[]=$_REQUEST['ItemName']; 

关于php - 将数据数组从 android 传递到 php 文件不会进入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14951366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com