Jump to content


Photo

booking query


  • Please log in to reply
4 replies to this topic

#1 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 29 April 2006 - 04:06 PM

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:


 $query = "INSERT INTO booking (booking_start_date, booking_end_date) VALUES ('$book_start','$book_end')";
         mysql_query($query, $connection) or die (mysql_error());


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:


<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>


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

#2 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 30 April 2006 - 04:42 AM

what's the problem....just enter it


$accomID=$_POST['accomID'];

$query = "INSERT INTO booking (booking_start_date, booking_end_date,accomID) VALUES ('$book_start','$book_end','$accomID')";


#3 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 30 April 2006 - 07:09 PM

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

#4 yaron160

yaron160
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 April 2006 - 07:27 PM

in the booking page put the $_POST['accommID'] as a hidden field:

echo '<input type="hidden" name="accommID" value="'.$_POST['accommID].'">';

then on the next page, after getting your dates, simply get that hidden field's value:

$accommID = $_POST['accommID'];

#5 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 30 April 2006 - 08:16 PM

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


$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();



that info is taken from the search results page and the booking code look like:


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());


thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users