Hello guys,

i wanna built a form which user can enter a list of fruits in it and send to database with BLOB parameter in a same field.example:

apple, grape, orange, banana, blackberry, avocado - from form

to fruit_list[BLOB]

anyone knows how to build the form which users can enter 1 by 1 before send to database

6 Years
Discussion Span
Last Post by Wraithmanilian

Well, there is a way to place the array into the database so that the array can be retrieved. First, use checkboxes in your form, like so:

<p>Apple <input type="checkbox" name="fruit[]" value="apple" /></p>
<p>Grape <input type="checkbox" name="fruit[]" value="grape" /></p>
<p>Peach <input type="checkbox" name="fruit[]" value="peach" /></p>
<p>Rock <input type="checkbox" name="fruit[]" value="rock" /></p>

When this is sent to php, you can retrieve the results like this:

$mycheckboxarray = $_POST['fruit'];

To save the array into a database, you'll need to serialize the array. Fixing the example above, it would look like:

$mycheckboxarray = serialize($_POST['fruit']);

Then, the array could be stored to the database, even in a text field. To re-use the data later, after pulling it from the database, you'll need to unserialize it, like so:

$myfruitdbarray = unserialize($row['fruit']);

Now, if all of the boxes had been checked, then in this example, the contents of $myfruitdbarray would be ('apple','grape','peach','rock').

Now, for the caveats. Using brackets in your form's input name will make the (x)html invalid on testing, so if that is important, then this is not the solution for you.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.