0
Hi, I’m making the following mistake: I am developing an application that checks a table of an external mysql database by sending the device’s IMEI returning a hardware id, but when debugging the code in the Asynchttpresponsehandler response line shows the following message (copied and pasted creating an html file). I wonder what I’m doing wrong in my code
Method that sends the IMEI to search
public void sendIMEIgetEquip(){
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
String IMEI = telephonyManager.getDeviceId();
JSONObject json = new JSONObject();
String path;
try {
json.put("imei", IMEI);
json.put("idEquip", 0);
} catch (JSONException e) {
e.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("imei",json);
path = "http://"+ip+"/mytolite/equipamento/getequipbyimei.php";
client.get(path, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
setMyEquip(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
dialog.hide();
if (statusCode == 404) {
Toast.makeText(getApplicationContext(), "Recurso requisitado não encontrado", Toast.LENGTH_SHORT).show();
} else if (statusCode == 500) {
Toast.makeText(getApplicationContext(), "Erro de servidor", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Erro inesperado [verifique sua conexão]", Toast.LENGTH_LONG).show();
}
}
});
}
Php code that handles json
<?php
/**
* Updates Sync status of Users
*/
include_once './db_functions.php';
//Create Object for DB_Functions clas
$db = new DB_Functions();
//Get JSON posted by Android Application
$json = $_POST["imei"];
//Remove Slashes
echo $json;
if (get_magic_quotes_gpc()){
$json = stripslashes($json);
}
//Decode JSON into an Array
$data = json_decode($json);
//Util arrays to create response JSON
$a=array();
$b=array();
//Loop through an Array and insert data read from JSON into MySQL DB
//Store User into MySQL DB
$equip = $db->getEquipByImei($data->imei);
//Based on inserttion, create JSON response
while ($row = mysqli_fetch_array($equip)) {
$b["id"] = $row["id"];
array_push($a,$b);
}
try{
if($a == ''){
echo 'jsonvazio';
}else {
echo json_encode($a);
}
}catch (Exception $e){
echo json_last_error_msg();
echo 'exceção: ', $e->getMessage(), "/n";
}
?>
php method that returns the device id based on the device’s IMEI
public function getEquipByImei($imei){
$result = mysqli_query($this->db->connect(), "SELECT idEquipamento FROM equipamentotablet WHERE imei = '$imei'");
return $result;
}
Note: Line 9 : $json = $_POST["Imei"]; (I believe this is where he is not finding the json index) Line 23 : $Equip = $db->getEquipByImei($data->Imei);
Thanks for your help.
It gave the same error, undefined index... somehow it’s not passing the json to the file, I think
– Allan Chrystian