Jump to content

Archived

This topic is now archived and is closed to further replies.

daniish

Howto concatenate <select> values and save in a single variable?

Recommended Posts

Hello,

I have the following date selector in an html form:

[code]
<form name=add_blog action="insert.php" method="post">

Title: <br><input type="text" size="79" id="title" method="post" name="title"></input> <br><br>

Date: <br>
<select id="daydropdown"></select>
<select id="monthdropdown"></select>
<select id="yeardropdown"></select> <br><br>
[/code]

How do i concatenate the DATE values and save them in a variable that i can assign to a field in my SQL database?


Many thanks for your help

Share this post


Link to post
Share on other sites
Use this as the html for your drop down menus
[code]<select id="dropdown['day']"></select>
<select id="dropdown['month']"></select>
<select id="dropdown['year']"></select>[/code]

Then you can access the day, month and year in a single variable called ($_POSt['dropdown'], which will hold an array of the three drop downs.
To access the day you can use $_POST['dropdown']['day'], for the the month you use $_POST['dropdown']['month'] and $_POST['dropdown'][year'] to get the year.

When you want to add them into the database, you can use implode function. Eg:
[code=php:0]$date = implode("-", $_POST['dropdown'];[/code]

What this will do is produce something like this: day-month-year

Does that help?


Share this post


Link to post
Share on other sites
Hmm i like arrays:)

do you think i can get your method to work with the javascript i am using:
[url=http://www.javascriptkit.com/script/script2/curdateform2.shtml]http://www.javascriptkit.com/script/script2/curdateform2.shtml[/url]

Cheers!

Share this post


Link to post
Share on other sites
Of course, you could just use a proper date picker and be done with it.

Share this post


Link to post
Share on other sites
Hey fenway,

what do you mean with a date picker ?
do you have a url with some more explanation ?

kind regards
anatak

Share this post


Link to post
Share on other sites
A custom control that a) makes sure you pick a valid date and b) places the full SQL-99 date string into a form field.

Share this post


Link to post
Share on other sites
ah ok.
I see. I thought you knew some mysterious function that did all the above for you.
custom = self written

thx
anatak

Share this post


Link to post
Share on other sites
That's generally the only way to get anything done properly ;-)

Share this post


Link to post
Share on other sites
true
and since I have a real dislike for programming anything time related I was more than interested to get my pawns on a killer function that does it for me ;)

Share this post


Link to post
Share on other sites

×

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.