Topic: Reservation details - Hotel

Hello,

I need some help here. I am going to build a Web site about a little hotel. It is actually a house with 6 rooms, nothing more. The client wants a reservation page, with simple information like: Name, telephone number, e-mail, dates of check-in and check out, number of rooms, gests per room, etc. I'm just concerned with two things:

1. For the dates, I'd like to add a calendar button, something like this:

http://ww w.holidayinn.com/h/d/hi/1/en /home#


2. I'd like to display the total total amount at the end of the reservation



Regards,

Eduardo

Vote up Vote down

Re: Reservation details - Hotel

Also,


After the user submits the information, I'd like him to see a feedback page just showing the information he just submitted. How can I tell php to fetch just that specific row?

Vote up Vote down

Re: Reservation details - Hotel

Hi edoplaza,

if you want to display the information in the same  page where you insert your data then user mysql_insert_id() after you run your insert query which fetches the lates id of data inserted.

If you wish to show the information in different pages then you can do the following.

<?php 
session_start();
//add a new row called sessionid in the table and while inserting the value put session_id() for it.
//eg: 
insert into your table (name,address,sessionid) values ("abc","bcd",'".session_id()."');
//then you can take out that record from the database any time until the user closes his browser.
//eg: 
select * from your table where sessionid='".session_id()."';
?>

Remember that this sessionid is valid for only once, this session id is always different for every user and is valid for only one user session.

Last edited by bishwadeep (August 27, 2009 11:55 pm)

Vote up Vote down

Re: Reservation details - Hotel

Thanks for the response,

I don't really understand what you mean. (where to put the codes, etc.). I created two pages just for you to see what I want and what I have so far:

http://ww w.puntabahareque.com/reservation.php


<?php require_once('Connections/connection1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO information (name, lastname) VALUES (%s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"));

  mysql_select_db($database_connection1, $connection1);
  $Result1 = mysql_query($insertSQL, $connection1) or die(mysql_error());

  $insertGoTo = "feedback.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>Put your information here:
<p>
<form action="<?php echo $editFormAction; ?>" method="post" id="form1">
  <table>
    <tr valign="baseline">
      <td align="right">Name:</td>
      <td><input type="text" name="name" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td align="right">Lastname:</td>
      <td><input type="text" name="lastname" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
<p>
<p>

</body>
</html>


And

http://ww w.puntabahareque.com/feedback.php


<?php require_once('Connections/connection1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_connection1, $connection1);
$query_Recordset1 = "SELECT information.name, information.lastname FROM information";
$Recordset1 = mysql_query($query_Recordset1, $connection1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>You just wrote:</p>
<p>Name: <?php echo $row_Recordset1['name']; ?></p>
<p>Last Name: <?php echo $row_Recordset1['lastname']; ?></p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>


Could you explain with more details?

Regards,

Eduardo

Vote up Vote down

Re: Reservation details - Hotel

Hi Edoplaza here is the code for form page. Note that you have to add a new field called sessionid (data type: text) in the information table. Note that the session id is used here so i am assuming that users will fill the form from different computer and different session. Session here means the interval of time when the user opens your page and closes the page.

<?php     
session_start();
?>
    <?php require_once('Connections/connection1.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    //add a new field in the information table as sessionid
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO information (name, lastname, sessionid) VALUES (%s, %s, %s)",GetSQLValueString($_POST['name'],"text"),GetSQLValueString($_POST['lastname'],"text"),GetSQLValueString(session_id(),"text"));
      mysql_select_db($database_connection1, $connection1);
      $Result1 = mysql_query($insertSQL, $connection1) or die(mysql_error());

      $insertGoTo = "feedback.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <p>Put your information here:
    <p>
    <form action="<?php echo $editFormAction; ?>" method="post" id="form1">
      <table>
        <tr valign="baseline">
          <td align="right">Name:</td>
          <td><input type="text" name="name" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Lastname:</td>
          <td><input type="text" name="lastname" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">&nbsp;</td>
          <td><input type="submit" value="Insert record" /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p>&nbsp;</p>
    <p>
    <p>

    </body>
    </html>

And here is the feedback page.

<?php 
session_start();
?>
<?php require_once('Connections/connection1.php'); ?>
<?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    mysql_select_db($database_connection1, $connection1);
    $query_Recordset1 = "SELECT information.name, information.lastname FROM information WHERE sessionid='".session_id()."'";
    $Recordset1 = mysql_query($query_Recordset1, $connection1) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <p>You just wrote:</p>
    <p>Name: <?php echo $row_Recordset1['name']; ?></p>
    <p>Last Name: <?php echo $row_Recordset1['lastname']; ?></p>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>

Last edited by bishwadeep (August 31, 2009 12:16 am)

Vote up Vote down

Re: Reservation details - Hotel

Hey, thank you very much, now I understand what you mean. However when I test the pages it gives me this:

Warning: Cannot modify header information - headers already sent by (output started at /home5/musicaen/public_html/puntabahareque/reservation1.php:4) in /home5/musicaen/public_html/puntabahareque/reservation1.php on line 51


I put 2 new pages with your code:

http://www.puntabahareque.com/reservation1.php

and

http://www.puntabahareque.com/feedback1.php

I checked line 51 and it has this code:

header(sprintf("Location: %s", $insertGoTo));


I don't know what that means


Regards,

Eduardo

Vote up Vote down

Re: Reservation details - Hotel

HI edoplaza,

I think you have a space before your <? starting tag. This type of warning message generally arises when there is a space before the opening tag.
-----------------------------------------------
ELIMINATE SPACE HERE <?

?>
-----------------------------------------------

Vote up Vote down

Re: Reservation details - Hotel

Thank you very much! Now it works. The only problem is that the feedback page is still showing the first line of the DataBase.
I checked on PHPmyAdmin and the information is being updated correctly, I mean, when you enter a new name and last name, they appear on the database but not on the feedback page.

Thanks again

Eduardo

Vote up Vote down

Re: Reservation details - Hotel

Hi edoplaza,
This is because you have test the page several time using the same session.
In real time this will not be the case. the user will fill the form once and he will close the browser.

if you want to use the page in the realtime mode then you have to clear the browser cookie and session each time after filling the form.

Currently you might notice that there might be same sessionid for different records in the database. This is because you are filling the form multiple times in the same user session.

Last edited by bishwadeep (September 1, 2009 10:45 pm)

Vote up Vote down

Re: Reservation details - Hotel

Thank you very much for your help!

Vote up Vote down