Jump to content

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


daniish

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
Link to comment
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?


Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.