2016-02-09 5 views
0

Цель состоит в том, что у меня есть успешный INSERT в таблице с именем «ReciboCliente», и это необходимо, и «userID», но мой Android-адрес отправляет только «имя пользователя». Я хочу сделать SELECT до INSERT, чтобы изменить «имя пользователя» для «userID» из таблицы «Agente». Это можно решить в веб-службе, но я не могу этого сделать.Как вставить данные из select в MYSQL с помощью JSON?

Это функция в веб-службы

public function insertPolizaCliente2(Request $request) 
{ 

    try { 


     //fetch table rows from mysql db 
     $connection = mysqli_connect("host", "user_name", "pass", "table"); 

     $sql = "select id from Agente where userID = ".$request->input('agentes')." limit 1"; 
     $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection)); 


     //create an array 
     //$emparray = array(); 
     if($row =mysqli_fetch_assoc($result)) 
     { 
      $agent[] = $row; 
     } 

     $agentes = json_decode($agent[]); 


     $id = DB::table('ReciboCliente') 
      ->insertGetId([ 
       'noRecibo' => $request->input('noRecibo'), 
       'agenteID' => $agentes, 
       'totalPrima' => $request->input('totalPrima'), 
       'montoRecibido' => $request->input('montoRecibido'), 
       'nombreCliente' => $request->input('nombreCliente'), 
       'ced_RNC_Cliente' => $request->input('ced_RNC_Cliente'), 
       'telefonoCelularCliente' => $request->input('telefonoCelularCliente'), 
       'telefonoOficinaCliente' => $request->input('telefonoOficinaCliente'), 
       'direccionCasaCliente' => $request->input('direccionCasaCliente'), 
       'direccionOficinaCliente' => $request->input('direccionOficinaCliente'), 
       'conceptoRecibido' => $request->input('conceptoRecibido'), 
       'formaPago' => $request->input('formaPago'), 
       'descripcionVehiculo' => $request->input('descripcionVehiculo'), 
       'chasis' => $request->input('chasis'), 
       'Placa' => $request->input('Placa'), 
       'cilindro' => $request->input('cilindro'), 
       'tonelada' => $request->input('tonelada'), 
       'pasajero' => $request->input('pasajero'), 
       'grua' => $request->input('grua'), 
       'carcelEspecial' => $request->input('carcelEspecial'), 
       'Placa' => $request->input('Placa'), 
       'cilindro' => $request->input('cilindro'), 
       'created_at' => \Carbon\Carbon::now()->toDateTimeString(), 
       'fechaHasta' => \Carbon\Carbon::now()->toDateTimeString(), 
       'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), 
      ]); 






     if(!empty($id)){ 
      $posts[] = array('data' => 'inserted'); 
     } else { 
      $posts[] = array('data' => 'not inserted'); 
     } 


     return $this->json_response('200', 'successful', $posts); 

    } 
    catch (Exception $e){ 
     return $this->json_response('400', 'error', 'bad request'); 
    } 

} 
+0

ли Юр производство дБ полномочия ??? – devpro

+3

Это @devpro. Я уже вошел в систему и украл все данные. Забавно, как их аватар «Аноним» ¯ \\ _ (ツ) _/¯ –

+0

Спасибо за ваши учетные данные БД. Нам просто нужна ваша кредитная карта, социальное обеспечение и номера паспортов, а также девичья фамилия вашей матери ... –

ответ

0

Вы не создаете правильный JSON. Изменить это:

if($row =mysqli_fetch_assoc($result)){ 
     $agent[] = $row; 
} 

$agentes = json_decode($agent[]); 

к этому:

if($row = mysqli_fetch_assoc($result)) { 
    $agent[] = $row['id']; 
} 

$agentes = json_decode($agent); 
+0

Не работает ни –

+0

Да , Но это не работает –

Смежные вопросы