Hotel Reservation Date Selector - php

I'm currently working on a hotel website which needs a section to select a booking based on the user's arrival and departure date selection. I am having an issue with getting the PHP to run and redirect to a URL with the drop down selector's values incorporated in.
So far for HTML I have:
<span name="checkIn">
<tr>
<td>
<span class="formtext">
<strong>Check-In:</strong>
</span>
</td>
<td>
<span class="custom-dropdown custom-dropdown--white custom-dropdown--small">
<select name="checkInMonth" class="custom-dropdown__select custom-dropdown__select--white">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05" selected="selected">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</span>
</td>
<td>
<span class="custom-dropdown custom-dropdown--white custom-dropdown--small">
<select name="checkInDate" class="custom-dropdown__select custom-dropdown__select--white">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11" selected="selected">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
</span>
</td>
<td>
<span class="custom-dropdown custom-dropdown--white custom-dropdown--small">
<select name="checkInYear" class="custom-dropdown__select custom-dropdown__select--white">
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2016">2017</option>
<option value="2016">2018</option>
<option value="2016">2019</option>
<option value="2016">2020</option>
<option value="2016">2021</option>
<option value="2016">2022</option>
<option value="2016">2023</option>
<option value="2016">2024</option>
<option value="2016">2025</option>
<option value="2016">2026</option>
<option value="2016">2027</option>
<option value="2016">2028</option>
<option value="2016">2029</option>
<option value="2016">2030</option>
<option value="2016">2031</option>
<option value="2016">2032</option>
<option value="2016">2033</option>
<option value="2016">2034</option>
<option value="2016">2035</option>
</select>
</span>
</td>
</tr>
</span>
<tr>
<td>
Book Now
</td>
</tr>
and for PHP:
<?php
$checkInMonth = $_POST['checkInMonth'];
$checkInDate = $_POST['checkInDate'];
$checkInYear = $_POST['checkInYear'];
$checkOutMonth = $_POST['checkOutMonth'];
$checkOutDate = $_POST['checkOutDate'];
$checkOutYear = $_POST['checkOutYear'];
header("Location: http://book.[REDACTED].com/[REDACTED]/selectRoom.do?propertyCode=XXXXX&arrivalDay=$checkInDate&arrivalMonthYear=$checkInYear$checkInMonth&departureDay=$checkOutDate&departureMonthYear=$checkOutYear$checkOutMonth");
?>
What am I doing wrong?

Based on the code you've pasted, it seems that you aren't using a form. Therefore, when you click on the "Book now" link no data are passed to your PHP page. Consider wrapping those elements inside a form, setting the action to bookengine.php, and having a proper submit button.

Related

Day of the Year Program

So I have this code that creates a drop down box to select a month, another drop down box to select the day, then a text field to type in a year. My question is what to do next in php to be able to select a certain month, day, and year to where, when i click "calculate," it will display what day of that year it is?
So for example, if i choose January 4 2015, when i click calculate, i want it to display 4 since it is the 4th day of the calendar year. How do I do that?
<form action="calc.php" method="post">
Month: <select name="month">
<option value="january">January</option>
<option value="february">February</option>
<option value="march">March</option>
<option value="april">April</option>
<option value="may">May</option>
<option value="june">June</option>
<option value="july">july</option>
<option value="august">August</option>
<option value="september">September</option>
<option value="october">October</option>
<option value="november">November</option>
<option value="december">December</option>
</select>
Day: <select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input name="entry" type="text" size="10" placeholder="Year">
<input type="submit" value="Calculate">
</form>
You can use date:
echo date("z", strtotime('2015-01-04'));
But it returns:
The day of the year (starting from 0)
So you need to add 1 to the result.
you can try the below code to get the day of the date . here i am using the same page for the post. if you are using another page for posting (i mean action page) use the php inside that file,
HTML
<form action="#" method="post">
Month: <select name="month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">july</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day: <select name="day">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input name="year" type="text" size="10" placeholder="Year">
<input type="submit" name="submit" value="Calculate">
</form>
PHP
<?php
if(isset($_POST['submit']))
{
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
echo date("l", strtotime($date));
}
?>

PHP POST data not coming through with enctype="multipart/form-data"

I'm having trouble getting my form's post data to come through. As this code stands, the file uploads, but I don't have any post data for the other form fields. I noticed that if I get rid of multipart/form-data enctype, it will not upload (obviously) but I DO get the post data to come through for the other fields. Any ideas on why this is?
The page where this code occurs is index.php?page=page1&upload=1
<form enctype="multipart/form-data" action="?page=page1&upload=2" method="post">
Select Location: <select name="location">
<option>Select Location</option>
<option value="N">North</option>
<option value="S">South</option>
<option value="E">East</option>
<option value="W">West</option>
</select><br />
Upload File: <input name="ufile" type="file" id="ufile" size="50" /><br />
<b><u>Sunday</u></b> Date: <select name="month">
<option> - Month - </option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="day">
<option> - Day - </option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="year">
<?php
$optionyear = date("Y",time());
$currentyear = $optionyear;
while($optionyear != 1990) {
echo "<option value=\"".$optionyear."\"";
if($optionyear == $currentyear) {
echo " selected";
}
echo ">".$optionyear."</option>";
$optionyear--;
}
?>
</select><br />
<input type="submit" name="Submit" value="Upload" /><br />
</form>
Thanks!
U can get your upload data with $_FILES[] and other data with $_POST[]
Try
echo "<pre>";
print_r($_POST);
print_r($_FILES['ufile']);
echo "</pre>";
By the way where is close tag for <form> element?

Error posting form data to same page

I have some info that is listed out. One of those fields is submit_date which has the date an application was submitted. On top of this list, I wanted to make a form where with drop down menus we could choose an initial date and a final date and then the list would only show applications submitted between that time range. I got the sql to work and made the form but for some reason whenever I click submit the entire list disappears.
<form name="yearRange" action="index.php" method="post">
Year1:
<select name="year1">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
Month1:
<select name="month1">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day1:
<select name="day1">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
Year2:
<select name="year2">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
Month2:
<select name="month2">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day2:
<select name="day2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if ($DBConn->numRows() > 0) { ?>
<div align="center">
<table border="1" align="center">
<tr>
<td> </td>
<td> </td>
<td><strong>Name</strong></td>
<td><strong>Submit Date</strong></td>
</tr> <?php
$date1="";
$date2="";
if(isset($_POST['year1']) && isset($_POST['year2']) && isset($_POST['month1']) && isset($_POST['month2']) && isset($_POST['day1']) && isset($_POST['day2']))
{
$date1 = $_POST['year1']."-".$_POST['month1']."-".$_POST['day1'];
$date2 = $_POST['year2']."-".$_POST['month2']."-".$_POST['day2'];
}
else{
echo "error";
}
$query = "select * from table1 where submit_date > '$date1' AND submit_date < '$date2'";
$sortQuery = mysql_query($query);
while ($row1=mysql_fetch_assoc($sortQuery))
{
?>
<tr>
<td valign="top"><?php echo $row1['lname'] . ", " . $row1['fname'] . " " . $row1['mname']; ?></td>
<td valign="top"><?php echo date('Y-m-d', strtotime($row1['submit_date'])); ?></td>
<?php } ?>
</tr> <?php
?>
</table>
</div>
<?php
} ?>

Drop-down values

I got two php files the Add.php and Edit.php
In Add.php. A drop-down list of date and gender.
<tr>
<td width="400" id="caption" style="text-align:right;">Birthdate</td>
<td>
<select id="monthID" name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="dayID" name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select id="yearID" name="year">
<option value="1970">1970</option>
<option value="1971">1971</option>
<option value="1972">1972</option>
<option value="1973">1973</option>
<option value="1974">1974</option>
<option value="1975">1975</option>
<option value="1975">1975</option>
<option value="1976">1976</option>
<option value="1977">1977</option>
<option value="1978">1978</option>
<option value="1979">1979</option>
<option value="1980">1980</option>
<option value="1981">1981</option>
<option value="1982">1982</option>
<option value="1983">1983</option>
<option value="1984">1984</option>
<option value="1985">1985</option>
<option value="1986">1986</option>
<option value="1987">1987</option>
<option value="1988">1988</option>
<option value="1989">1989</option>
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
</select>
</td>
</tr>
<tr>
<td width="400" id="caption" style="text-align:right;">Gender</td>
<td id="caption" style="text-align:left;">
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</td>
</tr>
If I choose April 3 2010 and Female in the drop-downs. And insert it in my table_1
Assume this are drop-downs
Birthdate: April 3 2010
Gender: Female
Now, when I want to update the record(s) in Edit.php the drop-down value should be also the same
Birthdate: April 3 2010
Gender: Female
But instead it gives me this
Birthdate: January 1 2013
Gender: Male
It seems like a default value whenever I visit in Edit.php. (January 1 2013 Male - are the first items in the dropdowns)
How can I make [April 23 2013 Female] appear in my drop-down Instead of the first values that I didn't choose.
Thanks and sorry for the title I can't think for a good title for this.
Use an if statement to compare each value with your record and then add "selected" to this option
here is the basic concept hope you catch the idea
<?php
$array = array(1=>"January",
2=>"February",
3=>"March",
4=>"April",
5=>"May",
6=>"June",
7=>"July",
8=>"August",
9=>"September",
10=>"October",
11=>"November",
12=>"December");
$stored_data = "2";
foreach($array as $key => $val) {
if($stored_data == $key) {
echo "<option value='$key' selected='1'>$val</option>";
} else {
echo "<option value='$key'>$val</option>";
}
}
?>

jQuery dynamiclly added from field wont submit

I have a bit of jQuery that allows people to add form fields dynamically based on the number of children they have.
var childCount = $('.newchildsub').length + 1;
$('.newchildsub:last').after($('.newchildsub:first').clone().removeAttr('id').attr('id', 'child-' + childCount).insertAfter('.newchildsub:last'));
$('#child-' + childCount).find('#childId').remove();
$('#child-' + childCount).find('#gender').attr('name', 'children[child-' + childCount + '][gender]').attr('value', '');
$('#child-' + childCount).find('#month').attr('name', 'children[child-' + childCount + '][month]').attr('value', '');
$('#child-' + childCount).find('#year').attr('name', 'children[child-' + childCount + '][year]').attr('value', '');
The code works prefect to add the fields and increase the name but when I click submit and print_r($_POST);, the dynamically created field is not there.
Below is an example of my html including the dynamically generated field (child-3), which is based of the first one as you can see in the jQuery.
<div id="child-1" class="newchildsub">
<h4>Gender: </h4><input type="hidden" id="childId" name="children[child-1][id]" value="394820">
<select name="children[child-1][gender]" id="gender">
<option value="">--</option>
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
<h4>Birthday: </h4>
<select name="children[child-1][month]" id="month">
<option value="">Month</option>
<option value="01">January</option>
<option value="02" selected>February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="children[child-1][year]" id="year">
<option value="">Year</option>
<option value="2012" selected>2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
</select><br><br>
</div>
<div id="child-2" class="newchildsub">
<h4>Gender: </h4>
<input type="hidden" id="childId" name="children[child-2][id]" value="394821">
<select name="children[child-2][gender]" id="gender">
<option value="">--</option>
<option value="male">Male</option>
<option value="female" selected>Female</option>
</select>
<h4>Birthday: </h4>
<select name="children[child-2][month]" id="month">
<option value="">Month</option>
<option value="01" selected>January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="children[child-2][year]" id="year">
<option value="">Year</option>
<option value="2012">2012</option>
<option value="2011" selected>2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
</select><br><br>
</div>
<div id="child-3" class="newchildsub">
<h4>Gender: </h4>
<select id="gender" name="children[child-3][gender]">
<option value="">--</option>
<option selected="" value="male">Male</option>
<option value="female">Female</option>
</select>
<h4>Birthday: </h4>
<select id="month" name="children[child-3][month]">
<option value="">Month</option>
<option value="01">January</option>
<option selected="" value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="year" name="children[child-3][year]">
<option value="">Year</option>
<option selected="" value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
</select><br><br>
</div>
According to your code you are changing the id, but not the name attribute for the cloned fields.
The name attribute has to be unique and that's why you don't see the dynamically added fields.
Add your name attribute into your jQuery code.
You have to manage name of your input element.
You can give them the name uniquely or give the name as un-indexed array like children[gender][]. Php will parse them and treat as array by creating index automatically for that. This link may help

Categories