cannot figure out why the error page gets triggered
<p>Why does <code>unexpectedReserveError.html</code> get triggered? As the code stands, does that mean the session token are not matching? I'm super bad at PHP ...</p>

<p><strong>EDIT</strong></p>

<p>Adding a description of the problem. As this code stands, it works fine for its purposes, ie, there's a htm form (second code set), and that transmits its variables to the backend page (first code set). What is puzzling to me is that the error page randomly happens. And a lot of people complain that the error page pops up, and thus abandon the page. </p>

<p>I've only been able to trigger the error page once, and only once, and even with that, there were no obvious clues why that happened. Thus my question on top is that .. since if you look at the code, you can see that there is a session token matching which if it doesn't work, it triggers the <code>unexpectedReserveError.html</code> page? (there are two error pages, the <code>header('location: URL/reserveError.html');</code> &amp; <code>header('location: URL/unexpectedReserveError.html');</code></p>

<p>Bottom line, I'm trying to figure out under what circumstances the unexpectedReserveError page is getting triggered because it's causing problems. </p>

<p><strong>BackendPage</strong></p>

<pre><code>&lt;?php

session_start();

  if ($_POST['token'] == $_SESSION['token']) {

        foreach($_POST as $key =&gt; $value) {
        if(ini_get('magic_quotes_gpc'))
          $_POST[$key] = stripslashes($_POST[$key]);
          $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
    }



                    $nights = $_POST['nights']; 
                    $arrivals = $_POST['arrivals'];
                    $male = $_POST['male']; 
                    $female = $_POST['female']; 
                    $rooms = $_POST['rooms']; 
                    $type = $_POST['type']; 
                    $name = $_POST['name']; 
                    $address = $_POST['address']; 
                    $zip = $_POST['zip']; 
                    $telephone = $_POST['telephone']; 
                    $email = $_POST['email_again']; 
                    $cell = $_POST['cell']; 
                    $message = $_POST['message']; 
                    $date = $_POST['date'];

                    require 'PHPMailerAutoload.php';

                  $mail = new PHPMailer;
                  $mail-&gt;CharSet = 'UTF-8';
                  $mail-&gt;isSMTP();  
                  //$mail-&gt;SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
                  $mail-&gt;Host = 'tls://smtp.gmail.com:587'; // Specify main and backup SMTP servers
                  $mail-&gt;SMTPAuth = true;                               // Enable SMTP authentication
                  $mail-&gt;Username = '';                 // SMTP username
                  $mail-&gt;Password = ''; 
                  $mail-&gt;addReplyTo( '', 'Hotel' );
                  $mail-&gt;AddCC('', 'Hotel');
                  $mail-&gt;addAddress(  $email, $first_name );
                  $mail-&gt;SetFrom('', '');
                  $mail-&gt;isHTML(true);                             
  // Set email format to HTML

                    $mail-&gt;Subject = 'Hotel Room Request';


                    $mail-&gt;Body = "&lt;table width='600'&gt;&lt;tr&gt;&lt;td colspan='2' height='20'&gt;&lt;p style='text-align:center; font-size:20px; color:#ddd; padding:0px; margin:0px;'&gt;Copy of Your Reserve Form&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                  ."&lt;tr&gt;&lt;td colspan='2'  height='80' width='600'&gt;&lt;p style='color:#d1502d;font-size:50px;text-align:center;padding:0px; margin:0px;'&gt;Hotel&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td colspan='2'  height='60' width='600' style='text-align:center; color:#606060;font-size:20px;padding:0px; margin:0px;'&gt;Los Angeles, CA &lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td colspan='2'  height='30' width='600' style='text-align:center;'&gt;&lt;h3 style='color:#d1502d; '&gt;Come and Explore  Los Angeles&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Number of Nights: &lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt; &lt;p style='font-size:20px; color:gray; padding:10px; margin:0px;'&gt;$nights&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Arrival Time: &lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px;'&gt;$arrivals&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Date:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $date&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Number of Guests - (Gender: male): &lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px;'&gt;$male&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Number of Guests - (Gender: female):&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $female&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Number of Rooms:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $rooms&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Type of Room:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $type&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Name:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $name&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Address:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $address&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Zip:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $zip&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Telephone:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $telephone&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Cell:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $cell&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Email:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $email&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:10px; margin:0px; text-align:right;'&gt;Your Message:&lt;/p&gt;&lt;/td&gt;&lt;td height='20' width='300'&gt;&lt;p style='font-size:20px; color:gray; padding:0px; margin:10px;'&gt; $message&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;"
                                                ."&lt;tr&gt;&lt;td colspan='2'  height='15' width='600'&gt;&lt;p style=' text-align:center;padding:0px; margin:0px;'&gt;&lt;a style='color:#d1502d;font-size:15px;text-align:center;padding:0px; margin:0px;text-decoration:none;'href='url'&gt;Visit Our Site&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";


                    $mail-&gt;AltBody = 'To view the message, please use an HTML compatible email viewer!';

                    if(!$mail-&gt;send()) {
                        header('location: URL/reserveError.html');

                    } else {
                        header('location: URL/reserveResult.html');

                    }

    }

    else {
            header('location: URL/unexpectedReserveError.html');
    }
</code></pre>

<p><strong>This is the html form page:</strong> </p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
   &lt;meta charset="utf-8"&gt;
  &lt;link href="favicon.ico" rel="icon" type="image/x-icon" /&gt;
  &lt;title&gt;Hotel&lt;/title&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/default.css"&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/default.date.css"&gt;  
  &lt;link href="css/bootstrap.min.css" rel="stylesheet" /&gt;
  &lt;link href="css/style.css" rel="stylesheet" /&gt;
    &lt;style type="text/css"&gt;
    .error {
      color:red;
    }
    body {
      padding-top: 146px;
      padding-top:175px;
    }
    .language_choice_english {
      padding-right: 1%
    }

    .language_choice_japanese {
        padding-right: 3%;
    }
  &lt;/style&gt;
&lt;/head&gt;


&lt;body&gt;

    &lt;script src="js/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
    &lt;script src="js/jquery.validate.js"&gt;&lt;/script&gt;
    &lt;script src="js/additional-methods.js"&gt;&lt;/script&gt;
      &lt;script&gt; 
          $(document).ready(function () {

              $('#reserveForm').validate({ 
                  rules: {
                      name: {
                          required: true
                      },
                      address: {
                          required: true
                      },
                      zip: {
                        required: true
                      },
                      telephone: {
                        required: true
                      },
                      email: {
                        required: true
                      },
                      email_again: {
                        equalTo: "#cemail"
                      },
                      nights: {
                        required: true
                      },
                      arrivals: {
                        required: true
                      },
                      male: {
                        required: true
                      },
                      female: {
                        required: true
                      },
                      rooms: {
                        required: true
                      },
                      type: {
                        required: true
                      },
                      date: {
                        required: true
                      }
                  }
              });
          });
      &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php
session_start(); //allows use of session variables

if (!isset($_SESSION['token']) &amp;&amp; $_SESSION['token'] == $_POST['token']) {

  $token = base64_encode(openssl_random_pseudo_bytes(32));
  $_SESSION['token'] = $token;
}

else {
  $token = base64_encode(openssl_random_pseudo_bytes(32));
  $_SESSION['token'] = $token;
}


?&gt;


  &lt;nav class="navbar navbar-default navbar-fixed-top"&gt;
    &lt;a class="brand pull-left" href="index.html"&gt;
            &lt;img id="Logo" src="./images/logo.gif" alt="Hotel"&gt;
            &lt;/a&gt;
  &lt;div class="container-fluid"&gt;
    &lt;!-- Brand and toggle get grouped for better mobile display --&gt;
    &lt;div class="navbar-header"&gt;
      &lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"&gt;
        &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;
      &lt;/button&gt;
       &lt;a class="navbar-brand" href="index.html"&gt;&lt;span id="overall_title"&gt;Hotel&lt;/span&gt;&lt;small id="description_of_city"&gt;Los Angeles&lt;/small&gt;&lt;/a&gt;
    &lt;/div&gt;

    &lt;!-- Collect the nav links, forms, and other content for toggling --&gt;
    &lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&gt;
      &lt;ul class="nav navbar-nav navbar-right"&gt;
        &lt;li&gt;&lt;a href="about.html"&gt;About&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="rooms.html"&gt;Rooms &amp; information&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="reserve.php"&gt;Book to Reserve&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="location.html"&gt;Location Info&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="additional.html"&gt;Additional Info&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="contact.php"&gt;Contact&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;&lt;!-- /.navbar-collapse --&gt;
    &lt;ul class="nav navbar-nav navbar-right"&gt;
        &lt;p class="pull-right language_choice_english"&gt;&lt;a href="reserve.php"&gt;English&lt;/a&gt;&lt;/p&gt;
        &lt;p class="pull-right language_choice_japanese"&gt;&lt;a href="reserve-ja.php"&gt;&lt;span lang="ja"&gt;日本語&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
    &lt;/ul&gt;
  &lt;/div&gt;&lt;!-- /.container-fluid --&gt;
&lt;/nav&gt;

&lt;div id="main-container" class="col-xs-12"&gt;


  &lt;form class="form-horizontal"  method="POST" action="bookInformation.php" id="reserveForm" autocomplete="off"&gt;

 &lt;p&gt;&lt;a href="rules.html" target="_blank"&gt;Rules and Regulations of  Hotel&lt;/a&gt;&lt;/p&gt;

            &lt;div&gt;
            &lt;label&gt;* Required fields&lt;/label&gt;
            &lt;/div&gt;


            &lt;input type="hidden" name="token" value="&lt;?php echo $token; ?&gt;" /&gt;


            &lt;div class="form-group"&gt;
              &lt;label for="cnights" class="col-sm-2 control-label"&gt;* Number of Nights&lt;/label&gt;
              &lt;div class="col-sm-10"&gt;
              &lt;select id="cnights" class="form-control" name="nights"&gt;                 
                &lt;option value=""&gt;Number of Nights&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 1 ) echo 'selected' ; ?&gt; value="1"&gt;1&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 2 ) echo 'selected' ; ?&gt; value="2"&gt;2&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 3 ) echo 'selected' ; ?&gt; value="3"&gt;3&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 4 ) echo 'selected' ; ?&gt; value="4"&gt;4&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 5 ) echo 'selected' ; ?&gt; value="5"&gt;5&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 6 ) echo 'selected' ; ?&gt; value="6"&gt;6&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 7 ) echo 'selected' ; ?&gt; value="7"&gt;7&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 8 ) echo 'selected' ; ?&gt; value="8"&gt;8&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 9 ) echo 'selected' ; ?&gt; value="9"&gt;9&lt;/option&gt;
                &lt;option &lt;?php if ($nights == 10 ) echo 'selected' ; ?&gt; value="10"&gt;10&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
            &lt;/div&gt;


            &lt;div class="form-group"&gt;
              &lt;label for="carrivals" class="col-sm-2 control-label"&gt;* Time of Arrival&lt;/label&gt;
               &lt;div class="col-sm-10"&gt;
              &lt;select id="carrivals" class="form-control" name="arrivals"&gt;
                &lt;option value=""&gt;Time of Arrival&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 14 ) echo 'selected' ; ?&gt; value="14"&gt;14&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 15 ) echo 'selected' ; ?&gt; value="15"&gt;15&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 16 ) echo 'selected' ; ?&gt; value="16"&gt;16&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 17 ) echo 'selected' ; ?&gt; value="17"&gt;17&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 18 ) echo 'selected' ; ?&gt; value="18"&gt;18&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 19 ) echo 'selected' ; ?&gt; value="19"&gt;19&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 20 ) echo 'selected' ; ?&gt; value="20"&gt;20&lt;/option&gt;
                &lt;option &lt;?php if ($arrivals == 21 ) echo 'selected' ; ?&gt; value="20"&gt;21&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
            &lt;/div&gt;

          &lt;div class="form-group"&gt;
            &lt;label for="cdate" class="col-sm-2 control-label"&gt;* Check-In Date&lt;/label&gt;
              &lt;div class="col-sm-10"&gt;
                &lt;input class="datepicker" type="text" placeholder="Please pick a date" id="cdate" name="date"&gt;
              &lt;/div&gt;
          &lt;/div&gt;


           &lt;div class="form-group"&gt;
              &lt;label for="cmale" class="col-sm-2 control-label"&gt;* Number of People&lt;/label&gt;
               &lt;div class="col-sm-10"&gt;
              &lt;select id="cmale" class="form-control" name="male"&gt;
                &lt;option value=""&gt;Gender Male&lt;/option&gt;
                &lt;option &lt;?php if ($male === 0 ) echo 'selected' ; ?&gt; value="0"&gt;0&lt;/option&gt;
                &lt;option &lt;?php if ($male == 1 ) echo 'selected' ; ?&gt; value="1"&gt;1&lt;/option&gt;
                &lt;option &lt;?php if ($male == 2 ) echo 'selected' ; ?&gt; value="2"&gt;2&lt;/option&gt;
                &lt;option &lt;?php if ($male == 3 ) echo 'selected' ; ?&gt; value="3"&gt;3&lt;/option&gt;
                &lt;option &lt;?php if ($male == 4 ) echo 'selected' ; ?&gt; value="4"&gt;4&lt;/option&gt;
                &lt;option &lt;?php if ($male == 5 ) echo 'selected' ; ?&gt; value="5"&gt;5&lt;/option&gt;
                &lt;option &lt;?php if ($male == 6 ) echo 'selected' ; ?&gt; value="6"&gt;6&lt;/option&gt;
                &lt;option &lt;?php if ($male == 7 ) echo 'selected' ; ?&gt; value="7"&gt;7&lt;/option&gt;
                &lt;option &lt;?php if ($male == 8 ) echo 'selected' ; ?&gt; value="8"&gt;8&lt;/option&gt;
                &lt;option &lt;?php if ($male == 9 ) echo 'selected' ; ?&gt; value="9"&gt;9&lt;/option&gt;
                &lt;option &lt;?php if ($male == 10 ) echo 'selected' ; ?&gt; value="10"&gt;10&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
            &lt;/div&gt;


            &lt;div class="form-group"&gt;
              &lt;label class="col-sm-2 control-label"&gt;* Number of People&lt;/label&gt;
               &lt;div class="col-sm-10"&gt;
              &lt;select class="form-control" name="female"&gt;
                &lt;option value=""&gt;Gender Female&lt;/option&gt;
                &lt;option &lt;?php if ($female === 0 ) echo 'selected' ; ?&gt; value="0"&gt;0&lt;/option&gt;
                &lt;option &lt;?php if ($female == 1 ) echo 'selected' ; ?&gt; value="1"&gt;1&lt;/option&gt;
                &lt;option &lt;?php if ($female == 2 ) echo 'selected' ; ?&gt; value="2"&gt;2&lt;/option&gt;
                &lt;option &lt;?php if ($female == 3 ) echo 'selected' ; ?&gt; value="3"&gt;3&lt;/option&gt;
                &lt;option &lt;?php if ($female == 4 ) echo 'selected' ; ?&gt; value="4"&gt;4&lt;/option&gt;
                &lt;option &lt;?php if ($female == 5 ) echo 'selected' ; ?&gt; value="5"&gt;5&lt;/option&gt;
                &lt;option &lt;?php if ($female == 6 ) echo 'selected' ; ?&gt; value="6"&gt;6&lt;/option&gt;
                &lt;option &lt;?php if ($female == 7 ) echo 'selected' ; ?&gt; value="7"&gt;7&lt;/option&gt;
                &lt;option &lt;?php if ($female == 8 ) echo 'selected' ; ?&gt; value="8"&gt;8&lt;/option&gt;
                &lt;option &lt;?php if ($female == 9 ) echo 'selected' ; ?&gt; value="9"&gt;9&lt;/option&gt;
                &lt;option &lt;?php if ($female == 10 ) echo 'selected' ; ?&gt; value="10"&gt;10&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
            &lt;/div&gt;




            &lt;div class="form-group"&gt;
              &lt;label class="col-sm-2 control-label"&gt;* Number of Rooms&lt;/label&gt;
               &lt;div class="col-sm-10"&gt;
              &lt;select class="form-control" name="rooms"&gt;
                &lt;option value=""&gt;Number of Rooms&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 1 ) echo 'selected' ; ?&gt; value="1"&gt;1&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 2 ) echo 'selected' ; ?&gt; value="2"&gt;2&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 3 ) echo 'selected' ; ?&gt; value="3"&gt;3&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 4 ) echo 'selected' ; ?&gt; value="4"&gt;4&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 5 ) echo 'selected' ; ?&gt; value="5"&gt;5&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 6 ) echo 'selected' ; ?&gt; value="6"&gt;6&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 7 ) echo 'selected' ; ?&gt; value="7"&gt;7&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 8 ) echo 'selected' ; ?&gt; value="8"&gt;8&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 9 ) echo 'selected' ; ?&gt; value="9"&gt;9&lt;/option&gt;
                &lt;option &lt;?php if ($rooms == 10 ) echo 'selected' ; ?&gt; value="10"&gt;10&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class="form-group"&gt;
              &lt;label class="col-sm-2 control-label"&gt;* Type of Room&lt;/label&gt;
               &lt;div class="col-sm-10"&gt;
              &lt;select class="form-control" name="type"&gt;
                &lt;option value=""&gt;Type of Room&lt;/option&gt;
                &lt;option &lt;?php if ($type == B ) echo 'selected' ; ?&gt; value="B"&gt;B&lt;/option&gt;
                &lt;option &lt;?php if ($type == C ) echo 'selected' ; ?&gt; value="C"&gt;C&lt;/option&gt;
                &lt;option &lt;?php if ($type == D ) echo 'selected' ; ?&gt; value="D"&gt;D&lt;/option&gt;
                &lt;option &lt;?php if ($type == E ) echo 'selected' ; ?&gt; value="E"&gt;E&lt;/option&gt;
                &lt;option &lt;?php if ($type == F ) echo 'selected' ; ?&gt; value="F"&gt;F&lt;/option&gt;
                &lt;option &lt;?php if ($type == G ) echo 'selected' ; ?&gt; value="G"&gt;G&lt;/option&gt;
                &lt;option &lt;?php if ($type == H ) echo 'selected' ; ?&gt; value="H"&gt;H&lt;/option&gt;
                &lt;option &lt;?php if ($type == I ) echo 'selected' ; ?&gt; value="I"&gt;I&lt;/option&gt;
                &lt;option &lt;?php if ($type == J ) echo 'selected' ; ?&gt; value="J"&gt;J&lt;/option&gt;
                &lt;option &lt;?php if ($type == K ) echo 'selected' ; ?&gt; value="K"&gt;K&lt;/option&gt;
              &lt;/select&gt;
            &lt;/div&gt;
            &lt;/div&gt;

        &lt;div class="form-group"&gt;
            &lt;label for="cname" class="col-sm-2 control-label"&gt;* Name&lt;/label&gt;
             &lt;div class="col-sm-10"&gt;
                &lt;input class="form-control" placeholder="Name" id="cname" type="text" name="name" value="&lt;?php if(isset($name)) { echo $name; }?&gt;"&gt;
              &lt;/div&gt;
        &lt;/div&gt;


            &lt;div class="form-group"&gt;
                &lt;label for="caddress" class="col-sm-2 control-label"&gt;* Address&lt;/label&gt;
                 &lt;div class="col-sm-10"&gt;
                &lt;input class="form-control" id="caddress" placeholder="Address" type="text" name="address" value="&lt;?php if(isset($address)) { echo $address; }?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;


            &lt;div class="form-group"&gt;
                &lt;label for="czip" class="col-sm-2 control-label"&gt;* Zip&lt;/label&gt;
                 &lt;div class="col-sm-10"&gt;
                &lt;input id="czip" class="form-control" placeholder="Zip" type="text" name="zip" value="&lt;?php if(isset($zip)) { echo $zip; }?&gt;"&gt;
              &lt;/div&gt;
            &lt;/div&gt;


           &lt;div class="form-group"&gt;
                &lt;label for="ctelephone" class="col-sm-2 control-label"&gt;* Telephone Number&lt;/label&gt;
                 &lt;div class="col-sm-10"&gt;
                &lt;input id="ctelephone" class="form-control" placeholder="Telephone Number" type="text" name="telephone" value="&lt;?php if(isset($zip)) { echo $zip; }?&gt;"&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class="form-group"&gt;
                &lt;label for="ccellphonenumber" class="col-sm-2 control-label"&gt;Cell Phone Number&lt;/label&gt;
                 &lt;div class="col-sm-10"&gt;
                &lt;input id="ccellphonenumber" class="form-control" placeholder="Cell Phone Number" type="text" name="cell" value="&lt;?php if(isset($cell)) { echo $cell; }?&gt;"&gt;
              &lt;/div&gt;
            &lt;/div&gt;



            &lt;div class="form-group"&gt;
                &lt;label for="cemail" class="col-sm-2 control-label"&gt;* Email&lt;/label&gt;
                 &lt;div class="col-sm-10"&gt;
                &lt;input id="cemail" class="form-control" placeholder="Email" type="text" name="email"&gt;
              &lt;/div&gt;
            &lt;/div&gt;

           &lt;div class="form-group"&gt;
                &lt;label for="cemail" class="col-sm-2 control-label"&gt;* Email Address Confirmation&lt;/label&gt;
                 &lt;div class="col-sm-10"&gt;
                &lt;input id="cemail2" class="form-control" placeholder="Email" type="text" name="email_again"&gt;
              &lt;/div&gt;
            &lt;/div&gt;


          &lt;div class="form-group"&gt;
            &lt;label class="col-sm-2 control-label"&gt;Message&lt;/label&gt;
             &lt;div class="col-sm-10"&gt;
             &lt;textarea class="form-control" rows="3" name="message" value="&lt;?php if(isset($message)) { echo $message; }?&gt;"&gt;&lt;/textarea&gt;
           &lt;/div&gt;
          &lt;/div&gt;


    &lt;div class="form-group"&gt;
    &lt;div class="col-sm-offset-2 col-sm-10"&gt;
      &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;      

&lt;/form&gt;

&lt;/div&gt;


  &lt;footer class="col-xs-12 roomsFooter"&gt;  

    &lt;div class="row"&gt;
        &lt;div class="col-md-4"&gt;2015  Hotel -- All rights reserved&lt;/div&gt;
        &lt;div class="col-md-4"&gt;Terms of Use&lt;/div&gt;
       &lt;div class="col-md-4"&gt;Facebook / Twitter / Instagram &lt;/div&gt;
    &lt;/div&gt;  
  &lt;/footer&gt;

&lt;script src="js/picker.js"&gt;&lt;/script&gt;
&lt;script src="js/picker.date.js"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(function(){
  $('.datepicker').pickadate();
});
&lt;/script&gt;
  &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/scripts.js"&gt;&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>EDIT</strong></p>

<p><strong>Session Token Stuff from Second Code Set Above</strong></p>

<pre><code>&lt;?php
session_start(); //allows use of session variables

if (!isset($_SESSION['token']) &amp;&amp; $_SESSION['token'] == $_POST['token']) {

  $token = base64_encode(openssl_random_pseudo_bytes(32));
  $_SESSION['token'] = $token;
}

else {
  $token = base64_encode(openssl_random_pseudo_bytes(32));
  $_SESSION['token'] = $token;
}


?&gt;
</code></pre>

<p>And this: <code>&lt;input type="hidden" name="token" value="&lt;?php echo $token; ?&gt;" /&gt;</code></p>