我正在尝试将多个选择值插入数据库。
HTML
<select style="width:175px" id="first" multiple="true">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<div class="mid">
<button type="button" class='add'> > </button>
<button type="button" class='remove'> < </button>
<button type="button" class='add-all'> >>> </button>
<button type="button" class='remove-all'> <<< </button>
</div>
<div class="end">
<select style="width:175px" id="second" name="second[]" multiple="true">
</select>
</div>
<div style="clear:both;"></div>
Javascript:
$('.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');
});
PHP:(它只是 php 代码的一小部分)
$formvars['second'] = $this->Sanitize($_POST['second']);
$insert_query = 'insert into 'comments'(second) values ("' . $this->SanitizeForSQL($formvars['second']) . '",)';
它仅将单词“Array”插入数据库。任何想法?