PHP pass variables from form to php

I’m more of a front-end developer, so the back-end stuff sometimes stumps me.

I have copied over some code from an existing website but it’s not functioning as expected on the new website.

Read More

I’m working with a hotel booking widget. There is a form on the homepage for inputting check in and check out dates. When the submit button is clicked, the form links to an availability table of all the room available.

On the current website, the dates inputted on the form are passed through to the availability table. However, when I copied the code over, it no longer functions as that. What am I missing?

Here is the form code:

<script type="text/javascript">

jQuery(document).ready(function() {
    jQuery('.MyDate1').datepicker({
        dateFormat : 'dd/mm/yy'
    });

jQuery(document).ready(function() {
    jQuery('.MyDate2').datepicker({
        dateFormat : 'dd/mm/yy'
 minDate:  0,
onSelect: function(date){
var date2 = $('.MyDate2').datepicker('getDate');
            date2.setDate(date2.getDate()+1);
            $('.MyDate1').datepicker('setDate', date2);
    });

</script>

<?php 
// ==================================================
// Displays the Booking Panel Date selection options.
// ==================================================

// Set up some default Check-in/Check-out Dates.
$checkinToday = date('d/m/Y');
$checkoutTomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('Y'));
$checkoutTomorrow = date('d/m/Y', $checkoutTomorrow);
?>
              <form name="bookingform" action="https://www.clarionsuitesgateway.com.au/clarionhotel/booking-system/" method="post">
              <div class="booking-h3">Check Availability</div>
              <div class="booking-row">
                <div class="booking-label">Check In Date</div>
                <div class="booking-field"><input name="frmCheckin" id="frmCheckin" type="text" class="MyDate1" value="<?php echo $checkinToday; ?>" style="width:100%" /></div>
              </div>
              <div class="booking-row">
                <div class="booking-label">Check Out Date</div>
                <div class="booking-field"><input name="frmCheckout" id="frmCheckout" type="text" class="MyDate2" value="<?php echo $checkoutTomorrow; ?>" style="width:100%" /></div>
              </div>
              <div class="booking-row">
                <div class="booking-row-box">
                  <div class="booking-label">Adults</div>
                  <div class="booking-field">
                      <select id="frmAdults" name="frmAdults">
                        <?php for ($i = 1; $i <= 10; $i++): ?>
                                  <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                        <?php endfor; ?>
                      </select>            
                  </div>
                </div>
                <div class="booking-row-box">
                  <div class="booking-label">Children</div>
                  <div class="booking-field">
                      <select id="frmChildren" name="frmChildren">
                        <?php for ($i = 0; $i <= 10; $i++): ?>
                                  <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                        <?php endfor; ?>
                      </select>            
                  </div>
                </div>
                <br clear="all">
              </div>
              <div class="booking-row">
                <div class="booking-button">
                  <input type="submit" value="Check Availability" name="Send" alt="Check Availability" />
                  <input type="hidden" name="Submit" />
                </div>
              </div>              
              </form>

Here is the availability table it directs to:

<?php
// ==================================================
// BOOKING BUTTON specific page.
// ==================================================
// Set some default dates incase nothing is selected (we're not doing any error checking for this).
// Today
$CheckinDay = date('d');
$CheckinMonth = date('m');
$CheckinYear = date('Y');
// Tomorrow
$CurrentDate = date('Y/m/d');
$Tomorrow = strtotime('+1 day', strtotime($CurrentDate)) ;
$Tomorrow = date('d/m/Y', $Tomorrow);
$arrCheckoutDate = explode("/", $Tomorrow);
$CheckoutDay = $arrCheckoutDate[0];
$CheckoutMonth = date("M", mktime(0, 0, 0, $arrCheckoutDate[1], 1, 2012));
$CheckoutYear = $arrCheckoutDate[2];

$NumberAdults = 1;
$NumberChildren = 0;

if ( isset($_POST["Submit"]) ) 
{
    if ( strlen($_POST['frmCheckin']) )
    {
        $arrCheckinDate = explode("/", $_POST['frmCheckin']);
        $CheckinDay = $arrCheckinDate[0];
        $CheckinMonth = date("M", mktime(0, 0, 0, $arrCheckinDate[1], 1, 2012));
        $CheckinYear = $arrCheckinDate[2];
    }
    if ( strlen($_POST['frmCheckout']) )
    {
        $arrCheckoutDate = explode("/", $_POST['frmCheckout']);
        $CheckoutDay = $arrCheckoutDate[0];
        $CheckoutMonth = date("M", mktime(0, 0, 0, $arrCheckoutDate[1], 1, 2012));
        $CheckoutYear = $arrCheckoutDate[2];
    }
    $NumberAdults = $_POST['frmAdults'];
    $NumberChildren = $_POST['frmChildren'];
}
?>
<?php get_header(); ?>
<div id="ContentOuterContainer">
  <div id="ContentInnerContainerBookings">
       <?php while ( have_posts() ) : the_post(); ?>

                 <iframe src="https://www.thebookingbutton.com.au/xxx/properties/xxx?utf8=%E2%9C%93&locale=en&check_in_date=<?php echo $CheckinDay;?>+<?php echo $CheckinMonth;?>+<?php echo $CheckinYear;?>&check_out_date=<?php echo $CheckoutDay;?>+<?php echo $CheckoutMonth;?>+<?php echo $CheckoutYear;?>&number_adults=<?php echo $NumberAdults; ?>&number_children=<?php echo $NumberChildren; ?>&commit=Check+Availability" height="590" width="1047" frameborder="0" scrolling="yes" allowtransparency="true"></iframe>


       <?php endwhile; ?>
    <div class="clear"></div>
  </div>
</div>
<div class="gap"></div>
<?php get_footer(); ?>

When I direct the form to the existing availability table, the dates are passed through. But when I copy the availability table to the new website, it stops passing through the dates. Any idea what I’m missing?

Thanks!

Related posts

1 comment

  1. It may have something to do with the fields on the ‘new’ site’s table. Check to make sure they are the proper data type. Are you using MySQL? My guess is that you may not be connecting to the database properly. If it’s working on your local server but it won’t put any data into the new server table there is probably nothing wrong with the PHP or Javascript. Look into your database.

Comments are closed.