使用getStringExtra
發送到數據庫我的應用程序從mapActivity
接收區域名稱,然後包括與當前活動取得的字符串是General_Info
,需要發送到在線數據庫。無法使用數據排球
在PHP代碼中沒有錯誤。
我已經測試了使用wi-fi和數據的應用程序,但不幸的是,它總是返回「失敗」。
我不知道我的代碼有什麼問題。
附上我的代碼
StringRequest request=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(response.contains("SUCCESS")){
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "system error", Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> param=new HashMap<String, String>();
param.put("householdid",houseNo.getText().toString());
param.put("region", region);
param.put("totalmembers", totalMembers.getText().toString());
param.put("totalfemale", totalFemale.getText().toString());
param.put("totalmale", totalMale.getText().toString());
return param;
}
};
MySingleton.getInstance(General_Info.this).addToRequestQueue(request);
}
PHP代碼:
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
include_once("connect.php");
$householdId = $_POST['householdid'];
$region = $_POST['region'];
$totalMembers = $_POST['totalmembers'];
$totalFemale = $_POST['totalfemale'];
$totalMale = $_POST['totalmale'];
$result = mysqli_query($con,"INSERT INTO households (householdId,region,totalMembers,totalFemale,totalMale)
VALUES ('$householdId',' $region','$totalMembers','$totalFemale',' $totalMale')");
if($result == true) {
echo "SUCCESS";
}
else{
echo "FAILURE ";
}
}
mysqli_close($con);
我想你錯過了代碼:)在所有響應 –
認沽日誌收到(Log.d)並粘貼您所得到的響應。此外,在粘貼代碼時使用代碼按鈕,不要像以前那樣執行代碼,並附上圖片。 – jlively
使用日誌爲每個參數ü放,也記錄響應.. – Manish