Jump to content

Recommended Posts

Hey people..

 

I have this hobby listbox with up to near about 15 items where a user can select multiple item.

How can i insert all the items selected in the listbox?

 

Example Hobbies: If multiple hobbies are selected in the listbox and on press button how should i insert into database?

 

I saw this tutorial on the website.. in which .. if one item is select it will save one item only and if multiple item is selected, it puts "," between the items selected and then save into database.

but i cannot find it rite now.. so please help me .. how can i do it??

 

Link to comment
https://forums.phpfreaks.com/topic/144791-listbox-to-database/
Share on other sites

Page: test.php

<?php
if (isset($_POST['list']) && is_array($_POST['list'])) {
    $items = implode(", ", $_POST['list']);
    echo $items;
}
?>
<form action="test.php" method="POST">
<select size="4" name="list[]" multiple>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="4">Item 4</option>
</select>
<input type="submit" value="submit" />
</form>

 

Should do it, making the name of the select an array (adding the []) allows for you to post more than one element. Using the implode on that posted item will make it into one line, comma separated.

Link to comment
https://forums.phpfreaks.com/topic/144791-listbox-to-database/#findComment-759807
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.