Skip to main content
December 4, 2007
Question

Combine month, date, year to submit to database

  • December 4, 2007
  • 1 reply
  • 309 views
I've used DW 8 to insert and update a form. Works great! I figured I would go a step further and make sure the date is entetred in the correct format. On the form, I used drop-down select lists for the three fields. Even this works great!

When I try to combine the three form variables into one variable to submit and store in the database (not even sure if that's the right way), I can't figure out how to make it work using the way DW is submitting the form variables. I have spent an entire day trying to research this and figure it out. I've seen it done a lot on the web, I just can't find any examples now that I need it. Any help would be appreciated.

Code as follows:
This topic has been closed for replies.

1 reply

Inspiring
December 4, 2007
Razzled Puma wrote:
> When I try to combine the three form variables into one variable to submit and
> store in the database (not even sure if that's the right way), I can't figure
> out how to make it work using the way DW is submitting the form variables.

Your massive amount of code has been truncated in the process of
transferring your post to the newsgroup server, so I can't see your
form. However, the principle is very simple. You have done things
correct in the insert query:

$date_event_from = $_POST["fromDateYr"]."-";
$date_event_from .= $_POST["fromDateMo"]."-";
$date_event_from .= $_POST["fromDateDay"];
$date_event_to = $_POST["toDateYr"]."-";
$date_event_to .= $_POST["toDateMo"]."-";
$date_event_to .= $_POST["toDateDay"];

The easy way to play ball with Dreamweaver's server behaviors is to
select one field as populating the date. In other words, use fromDateYr
and toDateYr in the update record server behavior dialog box. Then add
this at the top of the page:

<?php
if ($_POST && isset($_POST["fromDateYr"]) && isset($_POST["toDateYr"])) {
$_POST["fromDateYr"] .= "-$_POST[fromDateMo]-$_POST[fromDateDay]";
$_POST["toDateYr"] .= "-$_POST[toDateMo]-$_POST[toDateDay]";
}
?>

This has the effect of building the dates in MySQL format, and
reassigning them to $_POST["fromDateYr"] and $_POST["toDateYr"]. The
Dreamweaver server behavior then treats the dates correctly.

Note that there are no quotes around fromDateMo and the other field
names inside the double-quoted string. Using quotes around the keys of
array elements inside a double-quoted string causes a parse error.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
December 5, 2007
David - Thanks for your response. This has been driving me crazy. I tried your recommendation, but I wasn't successful. Since I couldn't tell if the variable was even being created, I wrote two small php pages to test it. I admit that this may have introduced another set of problems, but I was trying to simplify things. Could you look at them and tell me where I might be going off course?

First is a simple form, using the drop down selects to populate the date.
Test_simpleform.php

The other page displays all of the fields passed from the form; or at least should.
Test_Stamps.php