Jump to content

Insert into database multiselect box values


Recommended Posts

I know it's maybe EASY but how can I insert datas into database from multi-select html form?

Here is the code:

<body><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
<input type="submit" value="Send" />
if ($test){
 foreach ($test as $t){echo 'You selected ',$t,'<br />';}

Any ideas how to modify the above code so I can INSERT INTO values from multi-select box?

Link to comment
Share on other sites

try with php code




  $result = '';

  if ($test){

    foreach ($test as $t){

    $result .= $t.',';



    $result = trim($result, ',');



  // write ur insert query with $result variable


I tried the your code vichu.1985. The problem is with this code, it only inserts the last selected item into database. But the problem is solved above this topic: http://www.phpfreaks.com/forums/index.php/topic,305122.msg1442995.html#msg1442995 ut THANX anyway

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.