:「通知:未定義指數:在C:\ XAMPP \ htdocs中\ hello.php第4行」。經過幾個小時的搞亂之後,我無法解決我的問題。的Android到PHP錯誤 - 不明指數
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');
?>
更新方法:
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代碼。
數據包嗅探器說...? –
試試print_r($ _ POST)來查看你發佈的內容。 (注意:使用$ _POST而不是$ _REQUEST因爲它更安全 - 當你有機會的時候你還應該檢查函數mysql_real_escape_string();) – Robbie
嗨,好像print_r($ _ POST)返回Array() – jersam515