Jump to content

puja

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

puja's Achievements

Member

Member (2/5)

0

Reputation

  1. hi 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. [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="calendar2.php">Calendar</a>     <a href="search2.php">Search Again</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"];     $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">                     <tr>                          <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>                          </tr>                          ';                           echo '                           <tr>                          <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>                          </tr>                          ';                 echo '</table>';                 echo ' ';                 echo '<center> <input type="submit" value="Confirm Booking"></center>';                 echo '</FORM>';                 //mysql_free_result($result3);                 //}             //else                 //{             //    echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';                   //}             mysql_close();             if(!$result)                 {                 echo "Booking not added</td></table>";                 }             }         else             {             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>"; } ?> [/code] hope someone knows how to display the fields correctly and calculate the price thanks
  2. no that still doesnt work what i was trying to explain was that the $type, $board, $sleeps and $pets_allowed have come from the choices that the user has made. however the description and price are not choices. they should just be the fields in the database for the row that was chosen for those choices
  3. sorry i didnt explain myself very well there all the other fields are php variables that have some data stored on them but description and price are not variables, i just need to to insert whatever is in the table for that row where the other variables are from (not sure if that explaination is any better!) code has now been changed to: [code]     $type = $_POST["select_type"];     $sleeps = $_POST["select_sleeps"];     $board = $_POST["select_board"];     $pets_allowed = $_POST["select_pets_allowed"]; $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">                     <tr>                          <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>Price</b></td>                          </tr>                          ';                           echo '                           <tr>                          <td align="left">'. $row['type']. '</td>                          <td align="left">'. $row['sleeps']. '</td>                          <td align="left">'. $row['board']. '</td>                          <td align="left">'. $row['description']. '</td>                          <td align="left">'. $row['pets_allowed']. '</td>                          <td align="left">'. $row['price']. '</td>                          </tr>                          ';                 echo '</table>';                 echo ' ';                 echo '<center> <input type="submit" value="Confirm Booking"></center>';                 echo '</FORM>'; [/code]
  4. hi im trying to get some values to be shown in a table and im sure most of you are thinking duh that is really easy but im having a mental block with it. i know how to get multiple lines to show but i only want the one specific line of results to show for the current variables. the code is: [code]     $type = $_POST["select_type"];     $sleeps = $_POST["select_sleeps"];     $board = $_POST["select_board"];     $pets_allowed = $_POST["select_pets_allowed"]; $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());             //$num = mysql_num_rows($result3);             //$num = 0;             //if ($num > 0)                 //{                 echo '<FORM METHOD="POST" ACTION="add_pay.php">';                 echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">                     <tr>                          <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>Price</b></td>                          </tr>                          ';                           echo '                           <tr>                          <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">'. price. '</td>                          </tr>                          ';                 echo '</table>';                 echo ' ';                 echo '<center> <input type="submit" value="Confirm Booking"></center>';                 echo '</FORM>'; [/code] description and price should be taken straight from the table thanks
  5. puja

    query error

    thanks but i dont think that query is going to work for what i am trying to do so i need to create a new one. the user would have already selected the accomm they want so then i need to check if the dates they have given are available for the accommodation they have chosen.
  6. hi im trying to do a query but i am getting the following error You 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 line 3 is just somewhere in query2 does anyone recognise wot is wrong with the syntax? wot i need the code to do is make sure that no-one can double book check if the start date is before the end date (this works fine) check if the dates are available according to the accommID if the dates are available then put the details into the booking table (the insert query which also works) [code] 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"];                  $date1 = $book_start; //booking start date         $date2 = $book_end; //booking end date         $timestamp1 = strtotime($date1);         $timestamp2 = strtotime($date2);                 //if the start date is after the end date                 if($timestamp1 > $timestamp2){                   echo "Please enter a Booking Start Date that is before the Booking End Date";                         }                         //if the start date is before the end date                         elseif ($timestamp1 < $timestamp2){                                                  //check if the dates given are both before or both after the dates that are already in the database then the accomm is available                         //set the flag to 1 so that no-one else can book for them same dates while this customer is going through the booking stages                         $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());                         $statment = "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";                         print $statment;                         $query3 = mysql_query($statment) or die(mysql_error());                         echo "The dates are available";                         }//closes elseif             elseif (!$result2){                 echo "The dates are not available";             }             $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>";               }              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 [/code] that query with the error obvioisly doesnt work and ive tried to echo out and print the variables aswell to see if that is the problem but it wont let me do that either because i cant get rid of the error at the top hope some1 knows wots wrong with it and also is the way i am trying to find out if the dates are available being approached in the right way? or am i just way off track?
  7. ok i'll post the code on here for all three of the pages i am trying to link i know the code isnt very good but i just need to try and get the functionality working thanks 4 ur help! search2.php [code] <html> <head> <title><?php echo "Search" ?></title> <link rel="stylesheet" type="text/css" href="template2.css"> <head> <body> <? session_start(); if(!isset($_SESSION[user_name])) { echo "<p><center>Please login to view this page.</p><p>&nbsp;</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 { require_once("config.php");      $connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");           mysql_select_db($db_name, $connection); ?> <table border="1" width="100%" height="226">   <tr>     <td width="22%" height="91" bgcolor="#0099FF">&nbsp;     <img alt ="[Company Logo]"     src="puj2.gif" width="100" height="100">     <p>     </td>     <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>&nbsp; <H1> Search </H1>     </td>   </tr>   <tr>     <td width="22%" height="123" bgcolor="#6699FF">&nbsp;       <div class="buttonscontainer">       <div class="buttons">       <a href="gen_homepage.php">Homepage</a>       <a href="register.php">Register</a>       <a href="calendar.php">Calendar</a>       <a href="weatherinfo.php">Weather Information</a>       <a href="travelinfo.php">Travel Information</a>       <a href="logout.php">Logout</a>       </div>       </div>     </td>     <td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>      &nbsp;           &nbsp;           &nbsp;           <?       $accommID = $_POST ["accommID"];        ?> <center>     <form name="search2.php" action="search_results2.php" method="POST">           <font face="arial" size ="1">     Type:     <select name="select_type">             <option value='Villa'>Villa</option>             <option value='Caravan'>Caravan</option>             <option value='Lodge'>Lodge</option>           </select>           &nbsp;           Sleeps:           <select name="select_sleeps">             <option value='2'>Up to 2</option>             <option value='4'>Up to 4</option>             <option value='6'>Up to 6</option>             <option value='8'>Up to 8</option>             <option value='10'>Up to 10</option>           </select> &nbsp; <br> <br>           Board:           <select name="select_board">             <option value='Full Board'>Full Board</option>             <option value='Half Board'>Half Board</option>             <option value='B & B'>B & B</option>             <option value='Self-Catering'>Self-Catering</option>           </select> &nbsp;           Pets Allowed:           <select name="select_pets_allowed">             <option value='Yes'>Yes</option>             <option value='No'>No</option>           </select> &nbsp;           <br> <br>           <input type="hidden" name="accommID" value="' . $accommID . '" />            <center> <input type="submit" value="Search"></center>   </form> </td> </table> <? } ?> </body> </html> [/code] search_results2.php [code] <html> <head> <title><?php echo "Search Results" ?></title> <link rel="stylesheet" type="text/css" href="template2.css"> <head> <body> <? session_start(); if(!isset($_SESSION[user_name])) { echo "<p><center>Please login to view this page.</p><p>&nbsp;</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 { require_once("config.php");      $connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");           mysql_select_db($db_name, $connection); ?>                                                 <table border="1" width="100%" height="226">   <tr>     <td width="22%" height="91" bgcolor="#0099FF">&nbsp;     <img alt ="[Company Logo]"     src="puj2.gif" width="100" height="100">     <p>     </td>     <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>&nbsp; <H1> Search Results</H1>     </td>   </tr>   <tr>     <td width="22%" height="123" bgcolor="#6699FF">&nbsp;       <div class="buttonscontainer">       <div class="buttons">       <a href="search2.php">Search Again</a>       <a href="logout.php">Logout</a>       </div>       </div>     </td>     <td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>          <?           $self = $_SERVER['PHP_SELF']; $accommID = $_POST ["accommID"]; $type = $_POST["select_type"]; $sleeps = $_POST["select_sleeps"]; $board = $_POST["select_board"]; $description = $_POST["description"]; $pets_allowed = $_POST["select_pets_allowed"]; //$query = "SELECT type, sleeps, board, description, pets_allowed FROM accommodation WHERE type = '$type' AND sleeps = '$sleeps' AND board = '$board' AND description= '$description' AND pets_allowed = '$pets_allowed'"; $query = "SELECT accommID, type, sleeps, board, description, pets_allowed FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed'"; $result = mysql_query ($query) or die(mysql_error()); $num = mysql_num_rows($result); if ($num > 0){              echo "<p>There is currently $num accommodation(s). </p>\n";               echo '<FORM METHOD="POST" ACTION="add_book.php">';               echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">               <tr>               <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>               </tr>               ';                              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){                 echo '               <tr>               <td align="left">'. $row['type']. '</td>               <td align="left">'. $row['sleeps']. '</td>               <td align="left">'. $row['board']. '</td>               <td align="left">'. $row['description']. '</td>               <td align="left">'. $row['pets_allowed']. '</td>               <td align=center><input type=radio name=accommID value="'.$row['accommID'].'"></td>               </tr>               ';               }               echo '</table>';               echo '&nbsp';               echo '<center> <input type="submit" value="Continue Booking"></center>';                              mysql_free_result($result);                              } else {                   echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';               }               echo '</FORM>';               mysql_close();               //$statment =mysql_query ("SELECT type FROM accommodation WHERE type = '$type' and sleeps ='$sleeps' and board ='$board' and pets_allowed = '$pets_allowed'");// WHERE type = '$type' AND sleeps = '$sleeps' AND board = '$board' AND pets_allowed = '$pets_allowed'");               //print $statment;               //$query = mysql_query($statment) or die(mysql_error()); ?>   </form> </td> </table> <? } ?> </body> [/code] and finally the last one is add_book.php [code] <?php session_start(); if(!isset($_SESSION[user_name])) { echo "<p><center>Please login to view this page.</p><p>&nbsp;</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 { require_once("config.php");      $connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");       mysql_select_db($db_name, $connection);          $self = $_SERVER['PHP_SELF'];          //$book_start = $_POST ["booking_start_date"];          //$len = strlen($book_start);          //if ($len > 0)          //{          $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')";          mysql_query($query, $connection) or die (mysql_error());          //} ?> <html> <head> <title><?php echo "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">&nbsp;     <img alt ="[Company Logo]"     src="puj2.gif" width="100" height="100">     <p>     </td>     <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>&nbsp; <H1> Add Booking </H1>     </td>   </tr>   <tr>     <td width="22%" height="123" bgcolor="#6699FF">&nbsp;      <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>&nbsp;</p>     <form action ="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">     <p align="center">&nbsp;</p>     <p align="center"><u>Booking Start Date (YYYY/MM/DD):</u>&nbsp;&nbsp;&nbsp; <input type="text" name="booking_start_date" size="20"></p>     <p align="center"><u>Booking End Date (YYYY/MM/DD) :</u>&nbsp;&nbsp;&nbsp; <input type="text" name="booking_end_date" size="20"></p>     <p>&nbsp;</p>     <p><input type="submit" value="Submit"></p>   </form>         </form> </td> </table> <? } ?> </body> </html> [/code] thank u for ur help! puja
  8. puja

    sessions

    hey dhrups u alrite? lol if u use the session stuff on ur login page does the login still work? the thing that is wrong with ur last script is that with this part: [code] session_start(); if(!isset($_SESSION[user_id])) { 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=home.php'>"; } else { } [/code] u need to close the else after ur script so at the end of ur page coz ur saying that if the session isnt set then redirect them to the login page otherwise u let them into the script. lol hope that helps if it dont let me know
  9. hey the booking start and end dates are coming from that booking page not the search page. so on the booking page where the query is there is this further down in the page: [code] <form action ="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">     <p align="center">&nbsp;</p>     <p align="center"><u>Booking Start Date:</u>&nbsp;&nbsp;&nbsp; <input type="text" name="booking_start_date" size="20"></p>     <p align="center"><u>Booking End Date:</u>&nbsp;&nbsp;&nbsp; <input type="text" name="booking_end_date" size="20"></p>     <p>&nbsp;</p>     <p><input type="submit" value="Submit"></p>   </form> [/code] also i havnt got the accommID going thru any of my pages as a hidden field. on my initial search page i just have the drop down lists for the choices and then on the search results page i have got the accommID hopefully going thru with the radio button and then on the booking script i havnt specified newhere that it is the accommID that was selected in the radio button. or should it already know that coz i passed it thru with the radio button?
  10. hi again now im having a different prob with it, after u did ur suggested changes it does put in the accommID but it puts the accommID on one record with empty dates and it puts the dates chosen by the user in a separate record with an empty acommID
  11. hey!! thank u!! ur a genius! it works finally!!! thanks again puja
  12. hey im still having problems trying to get my code working for a booking query that i am trying 2 do the booking is for holiday accommodation and the accommodation is searched for the the first page with details from an accommodation table which has the primary key accommID. then from those results a radio button is chosen to carry on with the booking for that accommodation. on this booking page the users need to put in the booking start date and booking end date which is to be stored in the booking table. the booking table has bookingID as the primary key and the accommID as a foreign key to link the to accommID's. but what i am having problems with is storing the accommID that corresponds to the accomm chosen in the booking table. i have tried to use hidden fields but it doesnt seem to work! the following code is for the search results page: i know i have used the hidden field twice but im not sure where it shud go, ive tried it in both places and it still doesnt work [code] $self = $_SERVER['PHP_SELF']; $accommID = $_POST["accommID"]; $type = $_POST["select_type"]; $sleeps = $_POST["select_sleeps"]; $board = $_POST["select_board"]; $description = $_POST["description"]; $pets_allowed = $_POST["select_pets_allowed"]; //$query = "SELECT type, sleeps, board, description, pets_allowed FROM accommodation WHERE type = '$type' AND sleeps = '$sleeps' AND board = '$board' AND description= '$description' AND pets_allowed = '$pets_allowed'"; $query = "SELECT type, sleeps, board, description, pets_allowed FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed'"; $result = mysql_query ($query) or die(mysql_error()); $num = mysql_num_rows($result); if ($num > 0){              echo "<p>There is currently $num accommodation(s). </p>\n";               echo '<FORM METHOD="POST" ACTION="add_book.php">';               echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">               <tr>               <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>               <input type="hidden" name="accommID" value="'.$accommID.'">               </tr>               ';                              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){                 echo '               <tr>               <td align="left">'. $row['type']. '</td>               <td align="left">'. $row['sleeps']. '</td>               <td align="left">'. $row['board']. '</td>               <td align="left">'. $row['description']. '</td>               <td align="left">'. $row['pets_allowed']. '</td>               <td align=center><input type=radio name=accommID value="'.$row['accommID'].'"></td>               </tr>               ';               }               echo '</table>';               echo '&nbsp';               echo '<center> <input type="submit" value="Continue Booking"></center>';                              mysql_free_result($result);                              } else {                   echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';               }               echo '<input type="hidden" name="accommID" value="'.$accommID.'">';               echo '</FORM>';               mysql_close(); [/code] and the code for the booking looks like: [code] $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')";          mysql_query($query, $connection) or die (mysql_error()); [/code] thanks
  13. hey i tried that but it still doesnt work my search results page now looks like: i know its got the hidden field in 2 places but im not sure where it shud go so im hoping u cud tell me [code] $self = $_SERVER['PHP_SELF']; $accommID = $_POST["accommID"]; $type = $_POST["select_type"]; $sleeps = $_POST["select_sleeps"]; $board = $_POST["select_board"]; $description = $_POST["description"]; $pets_allowed = $_POST["select_pets_allowed"]; $query = "SELECT type, sleeps, board, description, pets_allowed FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed'"; $result = mysql_query ($query) or die(mysql_error()); $num = mysql_num_rows($result); if ($num > 0){              echo "<p>There is currently $num accommodation. </p>\n";               echo '<FORM METHOD="POST" ACTION="add_book.php">';               echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">               <tr>               <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>               <input type="hidden" name="accommID" value="'.$_POST['accommID'].'">               </tr>               ';                              while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){                 echo '               <tr>               <td align="left">'. $row['type']. '</td>               <td align="left">'. $row['sleeps']. '</td>               <td align="left">'. $row['board']. '</td>               <td align="left">'. $row['description']. '</td>               <td align="left">'. $row['pets_allowed']. '</td>               <td align=center><input type=radio name=accommID value="'.$row['accommID'].'"></td>               </tr>               ';               }               echo '</table>';                              mysql_free_result($result);                              } else {                   echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';               }               echo '<center> <input type="submit" value="Continue Booking"></center>';               echo '<input type="hidden" name="accommID" value="'.$_POST['accommID'].'">';               echo '</FORM>';               mysql_close(); [/code] that info is taken from the search results page and the booking code look like: [code] require_once("config.php");      $connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");       mysql_select_db($db_name, $connection);          $self = $_SERVER['PHP_SELF'];          //$bookingID = $_POST ["_BookingID"];          //$len = strlen($bookingID);         // if ($len > 0)         // {          $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')";          mysql_query($query, $connection) or die (mysql_error()); [/code] thanks
  14. sorry i probably didnt explain it 2 well! on the first page which is for the search results the data is taken from the accommodation table which has the primary key accommID. a particular accomm is chosen thru that page by a radio button and then it goes to the booking page in which they have 2 enter the dates they want. accommID is used as a foreign key in the booking table so when they choose the dates i need it to select the accommID for the accommodation they chose on the search page
  15. hi im trying to do a query to add bookings to a table. ive got the basic query to add the start and end dates which looks like: [code] $query = "INSERT INTO booking (booking_start_date, booking_end_date) VALUES ('$book_start','$book_end')";          mysql_query($query, $connection) or die (mysql_error()); [/code] but i also need to to put in the accommodation id for the accommodation that the booking is for. the accommodation is selected on a previous page through a radio button which then uses the post method to get to the booking page. that looks like: [code] <tr>               <td align="left">'. $row['type']. '</td>               <td align="left">'. $row['sleeps']. '</td>               <td align="left">'. $row['board']. '</td>               <td align="left">'. $row['description']. '</td>               <td align="left">'. $row['pets_allowed']. '</td>               <td align=center><input type=radio name=accommID value="'.$row['accommID'].'"></td>               </tr> [/code] ive got the accommID as a field in my booking table aswell but how do i say that i want to put in the accommID for the accommodation selected with the radio button into the booking table aswell? hope that makes sense thanks
×
×
  • Create New...

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.