Note that there are some explanatory texts on larger screens.

plurals
  1. POHow insert multiple select values to database?
    primarykey
    data
    text
    <p>I am trying to insert multiple select values to database.</p> <p>HTML</p> <pre><code>&lt;select style="width:175px" id="first" multiple="true"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="mid"&gt; &lt;button type="button" class='add'&gt; &gt; &lt;/button&gt; &lt;button type="button" class='remove'&gt; &lt; &lt;/button&gt; &lt;button type="button" class='add-all'&gt; &gt;&gt;&gt; &lt;/button&gt; &lt;button type="button" class='remove-all'&gt; &lt;&lt;&lt; &lt;/button&gt; &lt;/div&gt; &lt;div class="end"&gt; &lt;select style="width:175px" id="second" name="second[]" multiple="true"&gt; &lt;/select&gt; &lt;/div&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt; </code></pre> <p>Javascript:</p> <pre><code>$('.add').click(function(){ $('#first option:selected').appendTo('#second'); }); $('.remove').click(function(){ $('#second option:selected').appendTo('#first'); }); $('.add-all').click(function(){ $('#first option').appendTo('#second'); }); $('.remove-all').click(function(){ $('#second option').appendTo('#first'); }); </code></pre> <p>PHP:(its only a small portion of the php code)</p> <pre><code>$formvars['second'] = $this-&gt;Sanitize($_POST['second']); $insert_query = 'insert into 'comments'(second) values ("' . $this-&gt;SanitizeForSQL($formvars['second']) . '",)'; </code></pre> <p>Its inserting only the word "Array" into database. Any idea?</p>
    singulars
    1. This table or related slice is empty.
    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