Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON_decode problem with array posted to CodeIgniter
    text
    copied!<p>I am certain I am making a simple mistake... but simply can't find it. </p> <p>Ultimately I am posting a JSON array from an Android app (that part is working), but for the time being I am simply testing between two PHP pages (1: test PHP page with basic form, and 2: the CodeIgniter final destination) Here is what I have:</p> <p>At the form page:</p> <pre><code>&lt;form action="bambooinvoice/index.php/api2/newinvoice/4/0/0" method="post"&gt; &lt;?php $array = array("items"=&gt;array( "taxable"=&gt;1, "quantity"=&gt;1, "amount"=&gt;123.99, "work_description"=&gt;"this is a test")); $json = json_encode($array); ?&gt; &lt;input type="hidden" name=json value=&lt;?php $json ?&gt; /&gt; &lt;input type="submit" name="btnSendForm" value="Send" /&gt; &lt;/form&gt; </code></pre> <p>This creates (which looks good to me):</p> <pre><code>{"items":{"taxable":1,"Quantity":1,"amount":123.99,"work_description":"this is a test"}} </code></pre> <p>On the codeIgniter side, I have:</p> <pre><code>$input = $this-&gt;input-&gt;post('json'); $items = json_decode($input, TRUE); $amount = 0; foreach ($items as $item) // In case there are multiple 'items' { $taxable = (isset($item['taxable']) &amp;&amp; $item['taxable'] == 1) ? 1 : 0; $invoice_items = array( 'quantity' =&gt; $item['quantity'], 'amount' =&gt; $item['amount'], 'work_description' =&gt; $item['work_description'], 'taxable' =&gt; $taxable ); $this-&gt;_addInvoiceItem($invoice_items); //simply adding contents to DB } </code></pre> <p>In the end I receive the error: (i have received numerous errors actually in all my tweaking, but this is the one I can't seem to shake)</p> <pre><code>Message: Invalid argument supplied for foreach() </code></pre> <p>Edited - to correct a typo.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload