Jump to content

Insert into database multiselect box values


pahunrepublic

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>
</select>
<input type="submit" value="Send" />
</form>
<?php
$test=$_POST['test'];
if ($test){
 foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
?></body>

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

try with php code

 

<?php

  $test=$_POST['test'];

  $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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.