Solved

Entering Dates from separate dropdowns

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

23 Experts available now in Live!

Get 1:1 Help Now