Hi,
I created "scrollble Multi Select Option" as per below code.
<form name=myform>
<select name=mytextarea size=3 multiple>
<option name=one value=one> one </option>
<option name=two value=two> two </option>
<option name=three value=three> three </option>
<option name=four value=four> four </option>
</select>
</form>
---------------------------
but when i am inserting this value via php page into mysql table "tab1",only last selected value is getting inserted.
insert into tab(col1)
values($_POST['mytextarea ']);
plz let me know where i m wrong....thnx in advance
error..insert multiple value in "Select Option" in table?
Moderator: General Moderators
-
pradeepcarya
- Forum Newbie
- Posts: 5
- Joined: Tue Nov 08, 2011 4:36 am
Re: error..insert multiple value in "Select Option" in table
For use in PHP, to have an array of all selected items, you need to include a set of [] after the name so that PHP will put the items in an array (same for checkboxes)
(and also, the <option> tag does not support the name attribute, page won't validate)
Then in your code, $_POST['mytextarea'] will be an array of the items selected. You will have to code how to put this in your database (ie, is each one a separate row, or they getting entered all in the same field (ex. $strMyTextArea = implode(',',$_POST['mytextarea']); )
-Greg
(and also, the <option> tag does not support the name attribute, page won't validate)
Code: Select all
<form name="myform" method="post" action="#">
<select name="mytextarea[]" size="3" multiple="multiple">
<option value="one"> one </option>
<option value="two"> two </option>
<option value="three"> three </option>
<option value="four"> four </option>
</select>
</form> -Greg