Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: booking code

  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    booking code

    hi i realise that this code is a mess at the moment
    i cant even get it to work in the browser at the moment
    it gives me the error:

    Parse error: parse error, unexpected T_ELSE in C:\APACHE2\Apache2\htdocs\add_book.php on line 91

    which is the else in the lines which is before the form starts:

    else {
    $accommid = $_POST['accommID'];

    i have confused myself completly with all the if's and elseif's and the brackets that go with each.
    however i am trying to do a booking script that will search to see if the dates that the users have entered are avaialable for a particular accommodation.
    also i need to be able to solve the concurrent user problem to ensure that an accommodation cant be double booked.

    can any1 tell me if i am even along the right lines with wot i am trying to do with the following code because i have spent alot of time on it and now im not sure if i am approaching it in complelty the wrong way!

    Code:
    <?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 {
    ?>
    <html>
    <head>
    <title>Add Booking</title>
    <link rel="stylesheet" type="text/css" href="template2.css">
    <head>
    <body>
    
    <table border="1" width="100%" height="226">
      <tr>
        <td width="22%" height="91" bgcolor="#0099FF"> 
        <img alt ="[Company Logo]"
        src="puj2.gif" width="100" height="100">
        <p>
        </td>
        <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER> 
    
    <H1> Add Booking </H1>
    
        </td>
      </tr>
      <tr>
        <td width="22%" height="123" bgcolor="#6699FF"> 
         <div class="buttonscontainer">
          <div class="buttons">
        <a href="cust_homepage.php">Customer Homepage</a>
        <a href="calendar.php">Calendar</a>
        <a href="logout.php">Logout</a>
        </div>
        </div>
        </td>
        <td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>
    
         <p> </p>
    <?
    if(isset($_POST['submit'])){
    require_once("config.php");
    $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"];
             $query = "INSERT INTO booking (booking_start_date, booking_end_date, accommID) VALUES ('$book_start','$book_end','$accommID')";
               $result = mysql_query($query) or die (mysql_error());
                 if(!$result){
                 echo "Booking not added
                 </td>
                </table>";
                  } //closes if not result
                    //elseif {
                    $date1 = $book_start; //booking start date
                    $date2 = $book_end; //booking end date
    
                    $timestamp1 = strtotime($date1);
                    $timestamp2 = strtotime($date2);
    
                                if($timestamp1 > $timestamp2){
                                echo "Please enter a Booking Start Date that is before the Booking End Date";
                                }
                    //find if the dates they have entered are available for the accommID selected.  If the $booking start and $booking_end is less then then those already stored in teh field names mentioned
                    //then the flag will be 0 saying that the accomm is available
                                    if ($query2 = "select $accommID from booking group by $accommID
                                    having sum(case when ((booking_start_date < $book_start && booking_end_date < $book_end) || (booking_start_date > $book_start && booking_end_date > $book_end)
                                    then 0 else 1 end) = 0"){
                                    $result2 = mysql_query ($query2) or die(mysql_error());
    
                                    echo "The dates are available";
                                 
                                    //if the dates are available then join the type from accommodation with booking by matching the accommID in both tables
                                    //then check the dates again and if the flag is still 0 then allow booking else dates are not available.
                                 
                                     ($query3 ="select type from accommodation left join booking on accommID = accommID group by $accommID
                                     having sum (case when ((booking_start_date < $book_start and booking_end_date < $book_end) or (booking_start_date > $book_start and booking_end_date > $book_start)
                                     then 0 else 1 end) = 0") or die(mysql_error());
                                     //$result3 = mysql_query ($query3) or die(mysql_error());
                                     }//closes elseif
    
                elseif (!$result2){
                    echo "The dates are not available";
                }
                 echo "</td>
                </table>";
    
    else {
    $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>
      </form>
    </td>
    </table>
    <?
    
    } //closes else above
    echo "</body>
          </html>";
    } //close if submit
    }//closes sessions if
    ?>
    hope someone can help because i just seem to be more and more confused with it
    thanks

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    there is a problem on line 90. basically you are missing a }
    you currently have this
    PHP Code:
     }
                 echo 
    "</td>
                </table>"
    ;

    else {
    $accommid $_POST['accommID'];

    ?> 
    and it should be this
    PHP Code:
     }
                 echo 
    "</td>
                </table>"
    ;
    }
    else
    {
    $accommid $_POST['accommID'];

    ?> 
    but please note i don't know if that will fix the problem.
    i have a feeling you might have to many { orr not enough }
    easiest way to find out is to count how many of each you have. tip: they both should be the same.
    if they are the same then a problem is that like show above you have code between the } and the else.
    e.g. bad =
    PHP Code:
    if("Kelly Brook" == "Gorgeouse")
    {
     
    spankherbottom();
    }
    print 
    "that was good";
    else
    {
    Getsomeglasses();

    that will not work becuase i have some code betten the } and the elsee.

    how this helps
    Last edited by MRMAN; 05-05-2006 at 01:41 PM.

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok thanks that does help
    it solved the problem
    but ive changed the code slightly but it is still telling me that there is an error but the code that they say has the error isnt actually there anymore!
    it gives me the error:

    Please enter a Booking Start Date that is before the Booking End DateYou have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'then = 1 else = 0' at line 3

    but ive now changed my code to look like:

    Code:
    <?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 {
    ?>
    <html>
    <head>
    <title>Add Booking</title>
    <link rel="stylesheet" type="text/css" href="template2.css">
    <head>
    <body>
    
    <table border="1" width="100%" height="226">
      <tr>
        <td width="22%" height="91" bgcolor="#0099FF"> 
        <img alt ="[Company Logo]"
        src="puj2.gif" width="100" height="100">
        <p>
        </td>
        <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER> 
    
    <H1> Add Booking </H1>
    
        </td>
      </tr>
      <tr>
        <td width="22%" height="123" bgcolor="#6699FF"> 
         <div class="buttonscontainer">
          <div class="buttons">
        <a href="cust_homepage.php">Customer Homepage</a>
        <a href="calendar.php">Calendar</a>
        <a href="logout.php">Logout</a>
        </div>
        </div>
        </td>
        <td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>
    
         <p> </p>
    <?
    if(isset($_POST['submit'])){
    require_once("config.php");
    $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"];
             $flag = $_POST ["flag"];
             $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());
                 if(!$result){
                 echo "Booking not added
                 </td>
                </table>";
                  } //closes if not result
                    //elseif {
                    $date1 = $book_start; //booking start date
                    $date2 = $book_end; //booking end date
    
                    $timestamp1 = strtotime($date1);
                    $timestamp2 = strtotime($date2);
    
                                if($timestamp1 > $timestamp2){
                                echo "Please enter a Booking Start Date that is before the Booking End Date";
                                }
                    //find if the dates they have entered are available for the accommID selected.  If the $booking start and $booking_end is less then then those already stored in teh field names mentioned
                    //then the flag will be 0 saying that the accomm is available
                                    if ($query2 = "select $accommID from booking group by $accommID
                                    having sum(case when ((booking_start_date < $book_start && booking_end_date < $book_end) || (booking_start_date > $book_start && booking_end_date > $book_end)
                                    then $flag = 1 else $flag = 0"){
                                    $result2 = mysql_query ($query2) or die(mysql_error());
    
                                    echo "The dates are available";
                                 
                                    //if the dates are available then join the type from accommodation with booking by matching the accommID in both tables
                                    //then check the dates again and if the flag is still 0 then allow booking else dates are not available.
                                 
                                     ($query3 ="select type from accommodation left join booking on accommID = accommID group by $accommID
                                     having sum (case when ((booking_start_date < $book_start and booking_end_date < $book_end) or (booking_start_date > $book_start and booking_end_date > $book_start)
                                     then $flag = 1 else $flag =0") or die(mysql_error());
                                     //$result3 = mysql_query ($query3) or die(mysql_error());
                                     }//closes elseif
    
                elseif (!$result2){
                    echo "The dates are not available";
                }
                 echo "</td>
                </table>";
    }
    else {
    $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>
      </form>
    </td>
    </table>
    <?
    
    } //closes else above
    echo "</body>
          </html>";
     //close if submit
    }//closes sessions if
    ?>
    i have saved it script and closed the browser, logged in and out again but it still says it
    any suggestions y??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •