PDA

View Full Version : inserting form select w/ multiple options into mysql



Smirks
Wed 19th Feb '03, 11:25pm
Howdy,

I've decided to play around w/ php and mysql tonight and I'm trying to get something working, but I can't figure it out. I'm a beginner at this stuff, so perhaps I'm just doing it all wrong.

I have a simple database w/ one table that contains a name (varchar(30)) and a list of dates in the format mmddyyyy seperated by spaces. Example:


+--------+----------------------------------------------------------------+
| name | dates |
+--------+----------------------------------------------------------------+
| Joe | 04282003 04302003 05032003 07022003 07052003 07082003 07092003 |
+--------+----------------------------------------------------------------+

Now, I'm trying to create a from to input rows into that table in that format. I'm specifically having a hard time returning the dates to be inserted properly.

I have a select form like this:


<select name=\"dates[]\" size=10 multiple>
<option value=04282003>04/28/2003<br>
<option value=04302003>04/30/2003<br>
<option value=05032003>05/03/2003<br>
<option value=07022003>07/02/2003<br>
<option value=07052003>07/05/2003<br>
<option value=07082003>07/08/2003<br>
<option value=07092003>07/09/2003<br>
</select>

Now when the form submits it puts all the results into an array, afaik. How can I extract the values from this array so they are suitable for inserting into the database?

I've been workin on this for a few hours, and I think I'm close, but I just can't get it!

Thanks!

mr e
Thu 20th Feb '03, 12:16am
i think you'll have to assign each option a name and then use the name as the variable to put into the db

Icheb
Thu 20th Feb '03, 9:50pm
Why not use MySQL's possibilities for relational datastructure?

Have two tables:
Table 1 with the columns userid and username.
Table 2 with the columns userid and dates.

Read up on JOINs in your favorite MySQL book or on www.mysql.com .

Smirks
Thu 20th Feb '03, 10:40pm
Why not use MySQL's possibilities for relational datastructure?

Have two tables:
Table 1 with the columns userid and username.
Table 2 with the columns userid and dates.

Read up on JOINs in your favorite MySQL book or on http://www.mysql.com .
'Cause I'm not up to that point yet. :)

I want to make it work very easily and simply like this, then I'll work on ways to make it better. :)

Other than that, implode() was the function I was looking for. :)



$array = implode(" ","$dates");