簡體   English   中英

Android到PHP錯誤-無法識別的索引

[英]Android to PHP error- Unidentified Index

通過Android將數據發送到php服務器時,我遇到了以下錯誤:“注意:未定義的索引:第4行的C:\\ xampp \\ htdocs \\ hello.php中的IT”。 經過幾個小時的混亂,我無法解決我的問題。

hello.php:

<?php
mysql_connect("localhost","user","pass");
mysql_select_db("mmo");
$r=mysql_query("update players set X = '".$_REQUEST['IT']."' where 22=22");
if(!$r)
echo "Error in query: ".mysql_error();
mysql_close();
header('Refresh: 0.01; URL=http://localhost/hello.php');
?>

android中的更新方法:

public void UpdateSeverWithPlayer()
{List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
nameValuePairs.add(new BasicNameValuePair("IT","3"));
try{
     HttpClient httpclient = new DefaultHttpClient();
     HttpPost httppost = new HttpPost("http://10.0.2.2/hello.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());
    }}

我正在使用android模擬器,並且確實具有互聯網許可。 一如既往的幫助非常感謝。 編輯1:看來問題出在android而不是php代碼中。

您不會以某種方式正確地發送查詢字符串,因此PHP端沒有$_REQUEST['IT'] 做一個var_dump($_REQUEST)看看會發生什么。 或者更好的是,不要使用$ _REQUEST。 這有點不安全。 最好使用與您的HTTP方法_GET或_POST直接相關的超全局變量。

同樣, Refresh標頭是非標准的。 它會起作用,但您不應該依賴它。 HTTP級別重定向使用Location:標頭。 刷新:是非標准的老式Netscape擴展。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM