...

View Full Version : combine form fields



JBLC
08-23-2007, 12:17 AM
Hello
If someone could help me out with this problem it would be appreciated.

I am trying to insert into my database a single date entry generated from three select boxes within a form. The select boxes give the options of day, month and year in the format of 01 March 2007 and each select box has the id of 'ind_date'. The corresponding database column is type DATE.

The code I am currently using is


$ind_date = '';
foreach($_POST['ind_date'] as $value) {
$ind_date .= $value . ' ';
}
$ind_date = trim($ind_date);


$ind_date = $_POST['ind_date'][0] . '' . $_POST['ind_date'][1] . '' . $_POST['ind_date'][2];

in association with the following query



$query = "INSERT INTO opsv10 (first_name, last_name, company, position, registered, ind_date) VALUES ('$fn', '$ln', '$cn', '$pos', NOW(), '$ind_date')";

but this keeps returning the following error

"Invalid argument supplied for foreach()"

All suggestions welcome.
Thanks
JBLC

Inigoesdr
08-23-2007, 12:19 AM
The name has to be "ind_date[]", not the id.

JBLC
08-23-2007, 12:28 AM
Brilliant, problem solved.

Top coder that man.

JBLC



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum