Pass Multiple Checkbox Values

M

Marc

Hi people, I have an idea I'm sure has been thought of before but I'm
not sure how to execute. I'm using PHP and HTMl and am thinking that
there must be an easy way to do this.

I want to have one varchar or text field hold the value of several
checkbox items as one string. For example, let's say I have 10 movies
and want to list them in a string for the person to state their top 3.
So if they check boxes 3, 5, and 8 the result will be 3 to start with
5 appended and 8 appended appearing as "3, 5, 8" in the text box.

There are various reasons I'm doing this and one is because I'm using
an existing script and trying to create new fields for entry and
retreival would be convoluted. This might actually be a reasonable
workaround. Thanks so much for your help...
 
J

Jeffrey Silverman

I want to have one varchar or text field hold the value of several
checkbox items as one string. For example, let's say I have 10 movies
and want to list them in a string for the person to state their top 3.
So if they check boxes 3, 5, and 8 the result will be 3 to start with
5 appended and 8 appended appearing as "3, 5, 8" in the text box.


Rename text boxes like so:

<input type="checkbox" name="movies[]" value="1">movie1

etc...

USe the PHP join() function liek so:

$string = join("," $movies);

Voila!
 
M

Marc

I want to have one varchar or text field hold the value of several
checkbox items as one string. For example, let's say I have 10 movies
and want to list them in a string for the person to state their top 3.
So if they check boxes 3, 5, and 8 the result will be 3 to start with
5 appended and 8 appended appearing as "3, 5, 8" in the text box.


Rename text boxes like so:

<input type="checkbox" name="movies[]" value="1">movie1

etc...

USe the PHP join() function liek so:

$string = join("," $movies);

Voila!

Thanks so much. It was a beast figuring out where to put it.
Evidently, I think you have a typo in the syntax which should be

$string = join(",", $movies);

Which has the extra comma as join(1,2) passes two variables. :)
Worked great....
 
J

JDS

Thanks so much. It was a beast figuring out where to put it. Evidently, I
think you have a typo in the syntax which should be

$string = join(",", $movies);

Yes, I did have a typo.
 
T

Toby Inkster

Marc said:
I want to have one varchar or text field hold the value of several
checkbox items as one string.

This is a bad idea and will cause you problems further down the line.
Google for "first normal form" and why it's a bad idea to violate it.
 
M

Marc

This is a bad idea and will cause you problems further down the line.
Google for "first normal form" and why it's a bad idea to violate it.

The idea has been working great but for the entries in several fields
I'm getting an error

"Duplicate entry '5' for key 1"

on several variations. Thanks for the info and I will check although
I'm not sure what this would have to do with normalizing a relational
dabase (I think that's what it means, first, second, third normal
forms...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top