Solved

Start and End Dates for a MySQL query from PHP form

Posted on 2009-07-03
3
264 Views
Last Modified: 2013-12-13
I want to have a simple calendar system on a form to choose a start and end date. This date needs to be passed to an SQL query that will limit the results of the query.

The form also has a bunch of checkboxes (works well) to select columns and various other things..

I found a calendar that should work:

http://www.triconsole.com/php/calendar_datepicker.php

but I can't seem to get the date out of the $_POST array, even though I know it is being passed properly to $_POST.

In the code below I have the code that should be putting the start date in to a variable (?) ($smalldate) and the end date into $bigdate.

When I var_dump var_dump($_REQUEST); I get an array, and when I var_dump($bigdate); I get NULL.

I am totally open to using a different method altogether. I need to have a easy input for dates, ie I don't want the user to have to enter a date manually but rather have the ability to choose with the mouse.

I would like to have the start and end dates end up in something I can use in my SQL query like this:
WHERE `datavalues`.`LocalDateTime` < '$bigdate' AND `datavalues`.`LocalDateTime` > '$smalldate'";

Thanks!
<?php
 

#

# This is my query page (part of it)

#

<form method="post" action="result.php" name="searchform">
 
 

	 //get class into the page

require_once('classes/tc_calendar.php');
 

//instantiate class and set properties

$myCalendar0=new tc_calendar("date0",true);

$myCalendar0->setIcon("images/iconCalendar.gif");

$myCalendar0->setDate(1,1,2008);

$myCalendar0->getDate();

$myCalendar0->dateAllow('2006-01-01','2008-12-31',false);

$myCalendar0->autoSubmit (true, "searchform");

$myCalendar1=new tc_calendar("date1",true);

$myCalendar1->setIcon("images/iconCalendar.gif");

$myCalendar1->setDate(1,1,2008);

$myCalendar1->getDate();

$myCalendar1->dateAllow('2006-01-01','2008-12-31',false);

$myCalendar1->autoSubmit (true, "searchform");
 

        //output the calendar

		$myCalendar0->writeScript();

		echo "   to   ";

		$myCalendar1->writeScript();

?>

# The submit button and end of the form are lower down but not shown here.
 
 

#

# This is in result.php

#
 

<?php

$smallDate = isset($_REQUEST["date0"]) ? $_REQUEST["date0"] : "";

$bigDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
 

var_dump($_REQUEST); # returns an array

var_dump($bigdate); #returns "NULL"

echo  $_POST["date0"]; # seems to give me the result I want "2008-01-01"

?>

Open in new window

DateCal.jpg
0
Comment
Question by:KJB01
3 Comments
 
LVL 7

Expert Comment

by:szewkam
ID: 24774598
well, maybe you want consider another way to get the date-picker. I'm talking about http://jqueryui.com/demos/datepicker/
When you submit a form you get a date from one text type input. Without any problem :)
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 250 total points
ID: 24774624
$bigdate and $bigDate are two different variables, case matters. Line 40 assigns to $bigDate, line 43 dumps $bigdate.
0
 

Author Closing Comment

by:KJB01
ID: 31599678
Thanks very much! Good eye! It worked right away.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to Generate log or file on inserting duplicate records in mysql 6 28
<? versus <?php 5 36
WordPress Themes 10 34
Form Processing in PHP 11 30
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
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 …

919 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

18 Experts available now in Live!

Get 1:1 Help Now