Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with insert value in database with json_encode
    primarykey
    data
    text
    <p>I want insert on a row of database table, following value with following php code(<code>foreach</code>) but after insert get following error, what do i do?</p> <p><strong>Values:</strong></p> <pre><code>&lt;div class="column"&gt; &lt;input type="text" name="start_date[1][]" value="1111"&gt; &lt;input type="text" name="end_date[1][]" value="1111"&gt; &lt;input type="text" name="price_change[1][]" value="1111"&gt; &lt;/div&gt; &lt;div class="column"&gt; &lt;input type="text" name="start_date[2][]" value="2222"&gt; &lt;input type="text" name="end_date[2][]" value="2222"&gt; &lt;input type="text" name="price_change[2][]" value="2222"&gt; &lt;/div&gt; &lt;div class="column"&gt; &lt;input type="text" name="start_date[3][]" value="3333"&gt; &lt;input type="text" name="end_date[3][]" value="3333"&gt; &lt;input type="text" name="price_change[3][]" value="3333"&gt; &lt;/div&gt; </code></pre> <p><strong>Php code:</strong></p> <pre><code> $residence_ups_input = $this-&gt;input-&gt;post('start_date'); $residence_upe_input = $this-&gt;input-&gt;post('end_date'); $residence_upc_input = $this-&gt;input-&gt;post('price_change'); var_dump($residence_ups_input); // output this is: nobool(false) $residence_p = array(); foreach ($residence_ups_input as $idx =&gt; $name) { //line 134 $residence_p[] = array( 'start_date' =&gt; $residence_ups_input[$idx], 'end_date' =&gt; $residence_upe_input[$idx], 'price_change' =&gt; $residence_upc_input[$idx] ); } ; $data = array( //'name' =&gt; $this -&gt; input -&gt; post('name'), 'residence_p' =&gt; json_encode($residence_p) ); $this-&gt;db-&gt;insert('tour_foreign', $data); </code></pre> <p><strong>Error:</strong></p> <blockquote> <p>A PHP Error was encountered<br> Severity: Warning<br> Message: Invalid argument supplied for foreach()<br> Filename: inser.php<br> Line Number: 134<br></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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