473,661 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A little help with POST and DATE fields

2 New Member
Hi,
I have a php form that I want to use to pass a user specified "start date" and "end date" to a mysql database to retrieve reservations.

I want the number of days up to and including the "end date" to be displayed for both of these scenarios:
1) The item is still on loan as of the "end date"
2) The item has already been returned as of the "end date"

Right now I have it working by specifying a "start date", but the "end date" is actually set to the "current date". This would be fine, but I might need to go back and select all reservations in July, which would mean a whole lot of extra days being tallied up to today.

So, here is my code. The problem I am having is that the user input is a string, which I must convert before subtracting it from the start date. How do I do this?

Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. // Get start date and format properly for query string
  2. $v_startdate = $_POST['sdate'];
  3. $x_startdate = "'" . $v_startdate . "'" ;
  4.  
  5. // Get end date and format properly for query string
  6. $v_enddate = $_POST['edate'];
  7. $x_enddate = "'" . $v_enddate . "'" ;
  8.  
  9.  
  10.  
  11. // make connection to database
  12. mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
  13.  
  14. mysql_select_db($dbName) or die( "Unable to select database $dbName");
  15.  
  16. // 1st part - If the reservation is greater than or equal to the start date but ends before current date
  17. // 2nd part - If the reservation is greater than or equal to the start date but ends after current date, I want to see up to current date
  18. $query = "SELECT li.fname Name, li.lname Last_Name, rs.name Equipment, rv.summary Project, (TO_DAYS( from_unixtime( rv.end_date ) ) - TO_DAYS( from_unixtime( rv.start_date ) )) + 1 Days_Out , rs.notes ID_Cost
  19. FROM reservations rv, resources rs, reservation_users ru, login li
  20. WHERE rs.machid = rv.machid
  21. AND ru.resid = rv.resid
  22. AND li.memberid = ru.memberid
  23. AND from_unixtime( rv.end_date ) <= CURRENT_DATE() 
  24. AND from_unixtime(rv.start_date) >= $x_startdate
  25. UNION
  26. SELECT li.fname Name, li.lname Last_Name, rs.name Equipment, rv.summary Project, (TO_DAYS( CURRENT_DATE( ) ) - TO_DAYS( from_unixtime( rv.start_date ))) + 1 Days_Out,  rs.notes ID_Cost
  27. FROM reservations rv, resources rs, reservation_users ru, login li
  28. WHERE rs.machid = rv.machid
  29. AND ru.resid = rv.resid
  30. AND li.memberid = ru.memberid
  31. AND from_unixtime( rv.end_date ) > CURRENT_DATE() 
  32. AND from_unixtime( rv.start_date ) < CURRENT_DATE()
  33. AND from_unixtime(rv.start_date) >= $x_startdate
  34. ORDER BY 4";
  35.  
  36.  
  37. $result = mysql_query($query);
  38.  
  39. // Determine the number of reservations
  40. $number = mysql_numrows($result);
  41.  
  42. // print the records
  43. print "<h3><font face=Arial>There are $number records between $v_startdate and $v_enddate:</h3>
  44.     <table cellpadding=5>
  45.     <tr bgcolor=black>
  46.       <td><font color=white><b>Name</b></font></td>
  47.       <td><font color=white><b>Equipment</b></font></td>
  48.       <td><font color=white><b>Project</b></font></td>
  49.       <td><font color=white><b>Days_Out</b></font></td>
  50.       <td><font color=white><b>ID_Cost</b></td></font></tr>";
  51.  
  52. for ($i=0; $i<$number; $i++) {
  53.      $Name = mysql_result($result,$i,"Name");
  54.      $Last_Name = mysql_result($result,$i,"Last_Name");
  55.      $Equipment = mysql_result($result,$i,"Equipment");
  56.      $Project = mysql_result($result,$i,"Project");
  57.      $Days_Out = mysql_result($result,$i,"Days_Out");
  58.      $ID_Cost = mysql_result($result,$i,"ID_Cost");   
  59. //     print "$a $b $c $d $e $f $g<br>";
  60.  
  61. if ($i%2 == 0) {
  62.         print "<tr bgcolor=lightgrey>";
  63.         } else {
  64.         print "<tr>";
  65.         }
  66.     print "<td>$Name $Last_Name</td>
  67.     <td>$Equipment</td>
  68.     <td>$Project</td>
  69.     <td align = center>$Days_Out</td>
  70.     <td>$ID_Cost</td></tr>"; 
  71. }
  72. print "</table>";
  73.  
  74. //print " $query " ;
  75.  
  76.  
  77. // $timestampRightNow = time();
  78. // print "$timestampRightNow";
  79. print $CURRENT_DATE;
  80.  
  81. // Close the database connection
  82. mysql_close();
  83. ?>
  84.  
  85. <p>
  86.  
Oct 13 '07 #1
3 1298
ak1dnar
1,584 Recognized Expert Top Contributor
You can use checkdate() function for validate the date format.
Tip: Better to set up list menus to select dd mm yyyy, instead of a text input box.
Oct 13 '07 #2
shmoopie
2 New Member
Thanks, I got it working :o)
Oct 14 '07 #3
ak1dnar
1,584 Recognized Expert Top Contributor
Thanks, I got it working :o)
Glad to here you got it working. And If you can post the answer here, It will help for the others, who is having the same problem. Thanks.
Oct 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2264
by: Dan Weeb | last post by:
Hi Guys, I really am a novice and found a script on webmonkey. Basically all I want to do is to add records to my database. In my database I have a table called research_main with the fields already created. I have tried to bodge a script to work for me. it doesn't. It looks as though it works but I get no data posted. What have I done wrong? If you want me to put a statement in anywhere to check something please let
3
3727
by: Ricardo Sanchez | last post by:
Hello, I'm trying to upload images to http://imageshac.us via a Python script. I have looked at the POST request with HTTPLiveHeaders Firefox extension when I upload an image, but I can't figure what's wrong. (if I disable the cookies in the browser, it still works, so it's not that).
16
3055
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a certificate at the end of the year. I have the code working fine, except for the fact that when I want to restrict the entries to awards between certain dates, even though I can use the restriction in the query that shows the actual records, when the...
9
3958
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
32
12505
by: robert d via AccessMonster.com | last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections are of the following structure: Dim wsName As DAO.Workspace Dim dbName As DAO.Database Dim rsName As DAO.Recordset Set wsName = DBEngine.Workspaces(0) Set dbName = wsName.OpenDatabase(CurrentProject.FullName) Set rsName = dbName.OpenRecordset("SQL Statement")
3
3332
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my side. I am trying to learn how to manipulate Dynamic Queries by forms via the example database: QrySampl.MDB, offered by Microsoft (as a learning tool, I suppose.) In particular, I am working with code from the example: "Query By Form (QBF) Using...
13
1706
by: Jack B | last post by:
I'm using Access 2002 to create a database for a small opera company that my wife is involved in, and I'm more than a bit rusty because I haven't created a new Access database since about 1999. So, I will probably have quite a few questions as I go through this, and hopefully this group will help me out. I will be creating this database for someone else to enter the data. I have a patron table with name, address, email, etc., and I...
3
2321
by: Ethan Furman | last post by:
len wrote: I've never had the (mis?)fortune to work with COBOL -- what are the files like? Fixed format, or something like a dBase III style? I
2
3006
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.