title: Post data using php
body: <p>I made a API to fetch and store data, I can fetch data without problem, but everything changes when I try to store data, when I send the data it returns <code>[{&quot;success&quot;:&quot;0&quot;}]</code>. In the beginning it worked well, used accepted to store data, but suddenly everything changed. I've tried everything, compare the new with the old, changed the code, tables, but even so it always returns <code>[{&quot;success&quot;:&quot;0&quot;}]</code> after comparing both (old and new) code I couldn't see much difference. What could I be doing wrong?</p>
  <p>Insert data:</p>
  <pre><code>function insertloin()
  {
      if(isset($_POST[&quot;loincode&quot;]))
      {
          $form_data = array(
              ':loincode'     =&gt;  $_POST[&quot;loincode&quot;],
              ':code'     =&gt;  $_POST[&quot;code&quot;],
              ':specie'       =&gt;  $_POST[&quot;specie&quot;],
              ':grade'        =&gt;  $_POST[&quot;grade&quot;],
              ':vesselname'       =&gt;  $_POST[&quot;vesselname&quot;],
              ':type'     =&gt;  $_POST[&quot;type&quot;],
              ':productformat'        =&gt;  $_POST[&quot;productformat&quot;],
              ':dateprocessed'        =&gt;  $_POST[&quot;dateprocessed&quot;],
              ':datebb'       =&gt;  $_POST[&quot;datebb&quot;],
              ':projectcode'      =&gt;  $_POST[&quot;projectcode&quot;],
              ':netweight'        =&gt;  $_POST[&quot;netweight&quot;],
              ':producttype'      =&gt;  $_POST[&quot;producttype&quot;],
              ':oldoc'        =&gt;  $_POST[&quot;oldoc&quot;]
              
          );
          $query = &quot;
          INSERT INTO loins 
          (loincode, code, specie, grade, vesselname, type, productformat, dateprocessed, datebb, projectcode, netweight, producttype, oldoc) VALUES 
          (:loincode, :code, :specie, :grade, :vesselname, :type, :productformat, :dateprocessed, :datebb, :projectcode, :netweight, :producttype, :oldoc)
          &quot;;
          $statement = $this-&gt;connect-&gt;prepare($query);
          if($statement-&gt;execute($form_data))
          {
              $data[] = array(
                  'success'   =&gt;  '1'
              );
          }
          else
          {
              $data[] = array(
                  'success'   =&gt;  '0'
              );
          }
      }
      else
      {
          $data[] = array(
              'success'   =&gt;  '0'
          );
      }
      return $data;
  }
  </code></pre>
  <p>Test:</p>
  <pre><code>    if($_GET[&quot;action&quot;] == 'insertloin')
  {
      $data = $api_object-&gt;insertloin();
  }
  </code></pre>
  <p>Action:</p>
  <pre><code>    if(isset($_POST[&quot;action&quot;]))
  {
      if($_POST[&quot;action&quot;] == 'insertloin')
      {
          $form_data = array(
                  'loincode'      =&gt;  $_POST[&quot;loincode&quot;],
                  'code'      =&gt;  $_POST[&quot;code&quot;],
                  'specie'        =&gt;  $_POST[&quot;specie&quot;],
                  'grade'     =&gt;  $_POST[&quot;grade&quot;],
                  'vesselname'        =&gt;  $_POST[&quot;vesselname&quot;],
                  'type'      =&gt;  $_POST[&quot;type&quot;],
                  'productformat'     =&gt;  $_POST[&quot;productformat&quot;],
                  'dateprocessed'     =&gt;  $_POST[&quot;dateprocessed&quot;],
                  'datebb'        =&gt;  $_POST[&quot;datebb&quot;],
                  'projectcode'       =&gt;  $_POST[&quot;projectcode&quot;],
                  'netweight'     =&gt;  $_POST[&quot;netweight&quot;],
                  'producttype'       =&gt;  $_POST[&quot;producttype&quot;],
                  'oldoc'     =&gt;  $_POST[&quot;oldoc&quot;]
          );
          $api_url = &quot;http://192.168.85.160/API/v2/api/test_api.php?action=insertloin&quot;;
          
          $client = curl_init($api_url);
          curl_setopt($client, CURLOPT_POST, true);
          curl_setopt($client, CURLOPT_POSTFIELDS, $form_data);
          curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
          $response = curl_exec($client);
          curl_close($client);
          $result = json_decode($response, true);
          foreach($result as $keys =&gt; $values)
          {
              if($result[$keys]['success'] == '1')
              {
                  echo 'insert';
              }
              else
              {
                  echo 'error';
              }
          }
      }
  </code></pre>
  <p>Please, help me find the bug.
  Kind regards,
  Abd</p>