Solved

Entering Dates from separate dropdowns

Posted on 2002-07-10
3
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:
Richard Quadling 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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 i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
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…

751 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