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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.