Jump to content


This topic is now archived and is closed to further replies.


price and displaying table again!!

Recommended Posts

on this script i need to calculate the price depending on the number of days that the booking has been made for and i need to show the booking details with the total price.
the price field that is stored has the price per say and then i am trying to calculate it through $date_diff.
however it does not calculate the price or show the details in the table for the booking that is about to be made

at the moment the table shows the columns with the word description under the description heading rather than the description from the table and the price is shown as 0.


<?php session_start();
if(!isset($_SESSION['user_name'])) { echo "<p><center>Please login to view this page.</p><p> </p> Please wait... You will automatically be redirected back to the login page";
echo "<META HTTP-EQUIV=Refresh CONTENT='3; URL=gen_homepage.php'>";
} else {
<title>Add Booking</title>
<link rel="stylesheet" type="text/css" href="template2.css">

<table border="1" width="100%" height="226">
    <td width="22%" height="91" bgcolor="#0099FF">
    <img alt ="[Company Logo]"
    src="puj2.gif" width="100" height="100">
    <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>

<H1> Add Booking </H1>

    <td width="22%" height="123" bgcolor="#6699FF">
     <div class="buttonscontainer">
      <div class="buttons">
    <a href="cust_homepage.php">Customer Homepage</a>
    <a href="calendar2.php">Calendar</a>
    <a href="search2.php">Search Again</a>
    <a href="logout.php">Logout</a>
    <td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>

     <p> </p>
        $connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");
        mysql_select_db($db_name, $connection);
    $accommID = $_POST ["accommID"];
    $book_start = $_POST ["booking_start_date"];
    $book_end = $_POST ["booking_end_date"];
    $type = $_POST["select_type"];
    $sleeps = $_POST["select_sleeps"];
    $board = $_POST["select_board"];
    $pets_allowed = $_POST["select_pets_allowed"];

//$date_diff = ($timestamp2 - $timestamp1)/(60 * 60 * 24);

//echo '<br>';
//echo 'days difference between '.$date2.' and '.$date1.' is '.$price;
    $flag = 0;

    $date1 = $book_start; //booking start date
    $date2 = $book_end; //booking end date

    $timestamp1 = strtotime($date1);
    $timestamp2 = strtotime($date2);
        $date_diff = ($timestamp2 - $timestamp1)/(60 * 60 * 24);
        $price = $_POST["price"] * $date_diff;
    //if the start date is after the end date
    if($timestamp1 > $timestamp2)
        $Message = "Please enter a Booking Start Date that is before the Booking End Date";
    elseif ($timestamp1 < $timestamp2)

        $query2 = "select sum(case when (`booking_start_date` < '{$book_start}' "; //"from booking where $book_end >= booking_start_date and $book_start <= booking_end_date");
        $query2.= "AND `booking_end_date` < '{$book_start}' OR ";
        $query2.= "`booking_start_date` > '{$book_end}' AND ";
        $query2.= "`booking_end_date` > '{$book_end}') ";
        $query2.= "THEN 0 ELSE 1 END) as `resultant` FROM `booking` ";
        $query2.= "WHERE `accommID` = {$accommID}";

        $result2 = mysql_query($query2) or die (mysql_error());
        $dateOK = mysql_fetch_array($result2, MYSQL_ASSOC);
        $dateOK = $dateOK["resultant"];

        if ($dateOK == 0)
            $query = "INSERT INTO booking (booking_start_date, booking_end_date, accommID, flag) VALUES ('$book_start','$book_end','$accommID','$flag')";
            $result = mysql_query($query) or die (mysql_error());
            echo "The dates are available";
            $query3 = "(SELECT accommID, type, sleeps, board, description, pets_allowed, price FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed')";
            $result3 = mysql_query ($query3) or die(mysql_error());

            $row = mysql_fetch_array($result3);

            //$num = 0;
            //if ($num > 0)
                echo '<FORM METHOD="POST" ACTION="add_pay.php">';
                echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">
                         <td align="left"><b>Type</b></td>
                         <td align="left"><b>Sleeps</b></td>
                         <td align="left"><b>Board</b></td>
                         <td align="left"><b>Description</b></td>
                         <td align="left"><b>Pets Allowed</b></td>
                         <td align="left"><b>Booking Start Date</b></td>
                         <td align="left"><b>Booking End Date</b></td>
                         <td align="left"><b>Price</b></td>

                          echo '
                         <td align="left">'. $type. '</td>
                         <td align="left">'. $sleeps . '</td>
                         <td align="left">'. $board . '</td>
                         <td align="left">'. 'description'. '</td>
                         <td align="left">'. $pets_allowed. '</td>
                         <td align="left">'. $book_start. '</td>
                         <td align="left">'. $book_end. '</td>
                         <td align="left">'. $price. '</td>


                echo '</table>';
                echo ' ';
                echo '<center> <input type="submit" value="Confirm Booking"></center>';
                echo '</FORM>';
            //    echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';

                echo "Booking not added</td></table>";
            echo "The dates are not available";
    echo "</td></table>";
    $accommid = $_POST['accommID'];
    <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type=hidden name=accommID value="<?=$accommid?>">
    <p align="center"> </p>
    <p align="center"><u>Booking Start Date (YYYY/MM/DD):</u>    <input type="text" name="booking_start_date" size="20"></p>
    <p align="center"><u>Booking End Date (YYYY/MM/DD) :</u>    <input type="text" name="booking_end_date" size="20"></p>
    <p> </p>
    <p><input type="submit" name=submit value="Submit"></p>

    } //closes else above
echo "</body>
hope someone knows how to display the fields correctly and calculate the price


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.