Android : PHP Notice: Undefined offset: 1 when trying inset data from array to mysql

on Sunday, March 8, 2015


I am creating an android app where user creates profile and it gets saved in to sqlite. when connected to internet, it sync to mysql. I am able to pass the data from sqlite to php as an array but am not able to insert it to mysql. Not sure what i am doing wrong since i am new to php. I feel the problem is with this line.



$res = $db->storeUser($data[$i]->PID,$data[$i]->AID, $data[$i]->Logo,$data[$i]->Name, $data[$i]->Phone, $data[$i]->Employeeid, $data[$i]->Jobtitle, $data[$i]->Email, $data[$i]->Companyname, $data[$i]->Address, $data[$i]->City, $data[$i]->Province, $data[$i]->Postal);


Any help with details would be really appreciated.



<?php
include_once './db_functions.php';
//Create Object for DB_Functions clas
$db = new DB_Functions();
//Get JSON posted by Android Application
$json = $_POST["usersJSON"];
//Remove Slashes
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();
$n=count($data);
print_r(array_values($data));
//Loop through an Array and insert data read from JSON into DB
for($i=0; $i<=$n; $i++){
error_log(print_r($n,true));
error_log(print_r($i,true));
$j=$data[$i]->PID;
error_log(print_r($j,true));
//Store User into DB
$res = $db->storeUser($data[$i]->PID,$data[$i]->AID, $data[$i]->Logo,$data[$i]->Name, $data[$i]->Phone, $data[$i]->Employeeid, $data[$i]->Jobtitle, $data[$i]->Email, $data[$i]->Companyname, $data[$i]->Address, $data[$i]->City, $data[$i]->Province, $data[$i]->Postal);

//Based on inserttion, create JSON response
if($res){
$b[“id”] = $data[$i]->PID;
$b[“syncstatus”] = 'yes';
array_push($a,$b);
}else{$b[“id”] = $data[$i]->PID;
$b[“syncstatus”] = 'no';
array_push($a,$b);}
}
//Post JSON response back to Android Application
echo json_encode($a);


Here is the error code


[08-Mar-2015 07:44:19 America/Denver] 1 [08-Mar-2015 07:44:19 America/Denver] 1 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 22 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 22 [08-Mar-2015 07:44:19 America/Denver] [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Undefined offset: 1 in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver] PHP Notice: Trying to get property of non-object in /home2/pctechni/public_html/mirphp/insertuser.php on line 25 [08-Mar-2015 07:44:19 America/Denver]


0 comments:

Post a Comment