Solved

Entering Dates from separate dropdowns

Posted on 2002-07-10
3
225 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

617 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