I have multiple textfields...
<input type="text" name="date1" id="date1" value="" />
<input type="text" name="date2" id="date2" value="" />
I want to insert each field into one database table column(date)
How is this done???
thanks,
Kevin.
I have multiple textfields...
<input type="text" name="date1" id="date1" value="" />
<input type="text" name="date2" id="date2" value="" />
I want to insert each field into one database table column(date)
How is this done???
thanks,
Kevin.
With a mysqlquery:
insert into TABLE (field1, field2) values ($date1, $date2);
Sorry,
Didn't explain myself properly.
I want to insert $date1 and $date2 into one field.
How is this done?
in one field, and one record? Or two records?
As two records.
insert into TABLE (field1) values ($date1);
insert into TABLE (field1) values ($date2);
Well I plan to add more fields later so is there any way I could create an array and loop??
Here's what I have but only inserts one date...
for ($j=0;$j<sizeof($date);$j++)
{
$date=$date[$j];
// Perform Update Query
$query = "Insert into date values(NULL, '".$date."', '".$course."')";
$result = mysql_query($query) or die(mysql_error());
}
And here's the textfield:
<input type="text" name="date[]" id="date1" value="" />
<input type="text" name="date[1]" id="date1" value="" />
<input type="text" name="date[2]" id="date1" value="" />
<input type="text" name="date[4]" id="date1" value="" />
//--
foreach($date as $key => value)
{
$result = mysql_query("insert into TABLE (field1) values ($value);
}
Great!! Thanks leatherback!
Out of curiosity, since the one field will contain multiple values, as it were, why not concatenate all the variable contents and then only do one database insert as opposed to several. Might help with performance. Unless there's some reason you don't do so. If you know that you're going to get several fields from a form, and you know they all have to go into one database field, concat them all together (I believe there's an array function for that, not sure. implode() maybe?), then just do one database call and be done with it.
Just a suggestion.
James