Solved

Entering Dates from separate dropdowns

Posted on 2002-07-10
3
188 Views
Last Modified: 2006-11-17
Hi

I'm trying to enter a date into a MySQL database using php via three dropdown lists on a web page - one for day, one for date and one for month.

I'm very much a php/mysql novice so any help much appreciated.

Thanks
0
Comment
Question by:RonnieBrown
  • 2
3 Comments
 

Author Comment

by:RonnieBrown
ID: 7143446
I should also say that the following is the code I'm using:

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insert_job")) {
  $insertSQL = sprintf("INSERT INTO job_book (JOB_NO, `DATE`, CLIENT, JOB_DESCRIPTION, CLIENT_CONTACT, CO_CONTACT) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['jobNum'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['yyyy'], "date"),
                       GetSQLValueString($HTTP_POST_VARS['client'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['job_desc'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['client_contact'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['co_contact'], "text"));

  mysql_select_db($database_jobConn, $jobConn);
  $Result1 = mysql_query($insertSQL, $jobConn) or die(mysql_error());

  $insertGoTo = "view.php";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

Where 'yyyy' is the value of one of the drop downs.  Basically I need to replace this with a concated string consisting of "yyyy", "mm" and "dd".

Thanks
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 100 total points
ID: 7145700
GetSQLValueString($HTTP_POST_VARS['yyyy'] . $HTTP_POST_VARS['mm'] . $HTTP_POST_VARS['dd'], "date"),

Some things to watch out for.

1 - mm and dd need to be 2 digits.

So, ...

<select name="mm">
<option value="01">January
<option value="02">February
<option value="03">March
<option value="04">April
<option value="05">May
<option value="06">June
<option value="07">July
<option value="08">August
<option value="09">September
<option value="10">October
<option value="11">November
<option value="12">December
</select>

and

<select name="dd">
<option>01
<option>02
<option>03
<option>04
...
<option>28
<option>29
<option>30
<option>31
</select>

are OK.

2 - Invalid dates.

I do not know the javascript to amend a select list, but you can check before the form is submitted using ...

<form name="EnterDate" onSubmit="CheckForm();">

and

<script language="JavaScript"><!--
function CheckForm
{
// test date is valid using
//  document.EnterDate.mm.selectedIndex + 1 === mm
// and
//  document.EnterDte.dd.selectedIndex + 1 === dd
//
// If the date is OK, then return true else return false;
}

Regards,

Richard Quadling.
0
 

Author Comment

by:RonnieBrown
ID: 7146344
Thanks mate - that works great.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now