Какао POST & amp; Вопрос php

У меня нет большого опыта работы с какао и Php

В настоящее время мне нужно решить проблему, когда я хочу передать данные с Ipad на мой сервер, конечно, это не работает.

Когда я проверил файл error_log на сервере, я обнаружил ошибку в строке … [07-Jun-2016 12:10:38] Предупреждение PHP: неверный аргумент для foreach () в / home / futchoco / public_html / WebService / subir_datos.php в строке 32, сразу после строки // цикл через json объекты для вставки в mysql

<?phpclass RedeemAPI {
private $db;
// Constructor - open DB connection
function __construct() {
$this->db = new mysqli('localhost', 'xxxx', '999', 'futchoco');
/* verificar la conexión */
if (mysqli_connect_errno()) {
printf("Conexión fallida: %s\n", mysqli_connect_error());
exit();
}
$this->db->autocommit(FALSE);
}

// Destructor - close DB connection
function __destruct() {
$this->db->close();
}
// Main method to redeem a code
function redeem() {
// Check for required parameters
$json = file_get_contents('php://input');
$obj = json_decode($json,true);
error_log(print_r($obj,true));
// prepare the query
$stmt = $this->db->prepare('INSERT INTO det_encuentro_appcedula (id_cliente,id_sucursal,id_torneo,id_jornada,id_juego,id_equipo,enc_locvis,id_jugador,denc_minuto,denc_gol,denc_roja,denc_amarilla,id_arbitro) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$stmt->bind_param('iiiiiiiiiiiii',$id_cliente,$id_sucursal,$id_torneo,$id_jornada,$id_juego,$id_equipo,$enc_locvis,$id_jugador,$denc_minuto,$denc_gol,$denc_roja,$denc_amarilla,$id_arbitro);
// loop througght he json objects to insert into mysql
foreach($obj as $assocArray) {
error_log(print_r($obj,true));
//$id = $assocArray['value1'];
//$name = $obj['nombre'];
$id_cliente = $obj['id_cliente'];
$id_sucursal = $obj['id_sucursal'];
$id_torneo = $obj['id_torneo'];
$id_jornada = $obj['id_jornada'];
$id_juego = $obj['id_juego'];
$id_equipo = $obj['id_equipo'];
$enc_locvis = $obj['enc_locvis'];
$id_jugador = $obj['id_jugador'];
$denc_minuto = $obj['denc_minuto'];
$denc_gol = $obj['denc_gol'];
$denc_roja = $obj['denc_roja'];
$denc_amarilla = $obj['denc_amarilla'];
$id_arbitro = $obj['id_arbitro'];
//error_log(print_r($id,true));
//error_log(print_r($name,true));
if (!$stmt->execute()) // execute the query´
{
error_log(print_r('Execute failed to run',true));
}else{
$stmt = $this->db->prepare('COMMIT');
$stmt->execute();
}
}
}
}// This is the first thing that gets called when this page is loaded
// Creates a new instance of the RedeemAPI class and calls the redeem method
$api = new RedeemAPI;
$api->redeem();

?>

Я думаю, проблема в коде какао, когда я запустил этот код

NSLog(@"JSON summary: %@", [[NSString alloc] initWithData:self.json
encoding:NSUTF8StringEncoding]);

У меня есть эти данные

2016-06-07 10:15:34.388 CedulaArbitral[3760:60b] JSON summary: [
{
"gol" : "1",
"id_jugador" : "10",
"sucursal" : "1",
"id_arbitro" : "33",
"locvis" : "L",
"amarilla" : "0",
"id_juego" : "2",
"cliente" : "1",
"id_torneo" : "11",
"id_equipo" : "34",
"roja" : "0",
"id_jornada" : "14",
"minuto" : "1"},
{
"gol" : "1",
"id_jugador" : "1",
"sucursal" : "1",
"id_arbitro" : "33",
"locvis" : "V",
"amarilla" : "0",
"id_juego" : "2",
"cliente" : "1",
"id_torneo" : "11",
"id_equipo" : "36",
"roja" : "0",
"id_jornada" : "14",
"minuto" : "1"},
{
"gol" : "1",
"id_jugador" : "6",
"sucursal" : "1",
"id_arbitro" : "33",
"locvis" : "V",
"amarilla" : "0",
"id_juego" : "2",
"cliente" : "1",
"id_torneo" : "11",
"id_equipo" : "36",
"roja" : "0",
"id_jornada" : "14",
"minuto" : "1"},
{
"gol" : "0",
"id_jugador" : "6",
"sucursal" : "1",
"id_arbitro" : "33",
"locvis" : "V",
"amarilla" : "1",
"id_juego" : "2",
"cliente" : "1",
"id_torneo" : "11",
"id_equipo" : "36",
"roja" : "0",
"id_jornada" : "14",
"minuto" : "25"}
]

Итак, код Какао для отправки данных на сервер

-(void) request
{
RequestPost *request = [[RequestPost alloc] init];
request.delegado = self;
NSString *postStr = [NSString stringWithFormat:@"datos=%@",self.json];
NSString *strUrl = @"http://www.futcho.com/WebService/subir_datos.php";
[request descargar:strUrl datosPost:postStr conId:100];
}

-(void)descargar:(NSString*)direccion datosPost:(NSString*)datos conId(NSInteger)id{
self.id = id;

NSURL *url            = [NSURL URLWithString:direccion];

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

NSString *strLength = [NSString stringWithFormat:@"%lu", (unsigned long)datos.length];

[req addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

[req addValue:strLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[datos dataUsingEncoding:NSUTF8StringEncoding]];self.conexion = [[NSURLConnection alloc] initWithRequest:req delegate:self];

if(self.conexion){
self.buffer = [NSMutableData data];
}
}

Я должен отправить данные в формате JSON на интерфейс Php, правильно? Но я думаю, что я отправляю данные NSString, не могли бы вы мне помочь?

С уважением

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …