Skip to main content
Known Participant
November 16, 2006
Question

Insert Date from drop-down menus

  • November 16, 2006
  • 2 replies
  • 1259 views
I've searched a few forums and haven't had any luck. Maybe someone can help ...

Using PHP/MySql, I have a form which inserts a record and it works well except for one thing. I have three drop down menu fields named sDay, sMonth, and sYear - I need to combine those three values and insert into a field in the db called startDate. From what I've read I guess I need to concatenate the values but I'm new to PHP and I'm unclear about how to tweak the Dreamweaver Insert Record code. I've attached the code that exists now.

Thanks to anyone who can give me a hand.


This topic has been closed for replies.

2 replies

Inspiring
November 16, 2006
rsquaredpgh wrote:
> I have a form which inserts a record and it works well except
> for one thing. I have three drop down menu fields named sDay, sMonth, and sYear
> - I need to combine those three values and insert into a field in the db called
> startDate. From what I've read I guess I need to concatenate the values but I'm
> new to PHP and I'm unclear about how to tweak the Dreamweaver Insert Record
> code. I've attached the code that exists now.

Amend the code like this:

if ((isset($HTTP_POST_VARS["MM_insert"])) &&
($HTTP_POST_VARS["MM_insert"] ==
"bookroom")) {
$startDate = $_POST['sYear'].'-'.$_POST['sMonth'].'-'.$_POST['sDay'];
$insertSQL = sprintf("INSERT INTO bookings (roomID, clientID, adults,
children, startDate) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['roomID'],
"text"),
GetSQLValueString($HTTP_POST_VARS['clientID'],
"text"),
GetSQLValueString($HTTP_POST_VARS['adults'],
"int"),
GetSQLValueString($HTTP_POST_VARS['children'],
"int"),
GetSQLValueString($startDate, "text"));

It looks as though you are using Dreamweaver MX, which used deprecated
PHP code. You may find that $HTTP_POST_VARS doesn't work on modern PHP
servers. It should be replaced by $_POST. MX 2004 and Dreamweaver 8 use
the recommended version.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Known Participant
November 16, 2006
Good to know!
Known Participant
November 16, 2006
Ok. I've done away with the drop down boxes in favor of a date picker. I'm now trying to convert the mm-dd-yyyy format to MySql format (yyyy-mm-dd) when the form variable is passed. I'm trying to use the split function to do this but so far I'm unsuccessful. Can someone look at my code and tell if they see where the problem is? Recordset produced is always based on the default values ( $startDate_rsAV = "01/03/2007" & $endDate_rsAV = "01/04/2007") and not the input values. I'm getting pretty frustrated as I've been at this all day.

Thanks.

Inspiring
November 16, 2006
rsquaredpgh wrote:

> I've searched a few forums and haven't had any luck. Maybe someone
> can help ...
>
> Using PHP/MySql, I have a form which inserts a record and it works
> well except for one thing. I have three drop down menu fields named
> sDay, sMonth, and sYear - I need to combine those three values and
> insert into a field in the db called startDate. From what I've read I
> guess I need to concatenate the values but I'm new to PHP and I'm
> unclear about how to tweak the Dreamweaver Insert Record code. I've
> attached the code that exists now.
>
> Thanks to anyone who can give me a hand.
>
>
>
>
> if ((isset($HTTP_POST_VARS["MM_insert"])) &&
> ($HTTP_POST_VARS["MM_insert"] == "bookroom")) {
> $insertSQL = sprintf("INSERT INTO bookings (roomID, clientID,
> adults, children) VALUES (%s, %s, %s, %s)",
> GetSQLValueString($HTTP_POST_VARS['roomID'],
> "text"),
> GetSQLValueString($HTTP_POST_VARS['clientID'], "text"),
> GetSQLValueString($HTTP_POST_VARS['adults'], "int"),
> GetSQLValueString($HTTP_POST_VARS['children'], "int"));
>
> mysql_select_db($database_connGR, $connGR);
> $Result1 = mysql_query($insertSQL, $connGR) or die(mysql_error());

Having written a couple of reservation systems I'd recommend you use a
date picker application - it's much easier for the end user and very
difficult to make mistakes

something like
http://www.javascriptkit.com/script/script2/tengcalendar.shtml for
example

HTH

--
Buzby
There's nothing more dangerous than a resourceful idiot
Known Participant
November 16, 2006
Thanks for the tip. I looked at the Date picker you suggested - looks good but it doesn't allow the yyyy-mm-dd format that MySql requires. Since you've done it before, what's the best way to convert it?