Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,679 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,201 people online right now. Registration is fast and FREE... Join Now!




Need help with database retrieval in PHP codes

 
Reply to this topicStart new topic

Need help with database retrieval in PHP codes

PHP_noob
post 8 Jun, 2008 - 09:21 AM
Post #1


New D.I.C Head

*
Joined: 5 Jun, 2008
Posts: 24

Hi there pls refer to the following codes

CODE

<?php
      include "dbFunction.php";
/*Array ( [spapackage] => 1 [name] => [email] => [telephone] => [hiddenField] => member_id,
password [member_id] => [day] => 1 [month] => Jan [year] => 2008 [time] => 1 [Submit] => Submit ) */
      $package = $_POST['spapackage'];
      $name = $_POST['name'];
      $email = $_POST['email'];
      $telephone = $_POST['telephone'];
      $member = $_POST['member_id'];
      $day = $_POST['day'];
      $month = $_POST['month'];
      $year = $_POST['year'];
      $time = $_POST['time'];
      $roomId = "";
      $location="/paradigm/thankyou.html";
      $con = connect();
      $rs3 = mysql_query("Select * from room_aspara where packageId = '".$package."'");
      //echo "Select * from room where packageId = '".$package."'";

      while ($row3 = mysql_fetch_array($rs3))
      {
           $rs1 = mysql_query("Select count(*) as 'count' from reservation_aspara where time = '". $time ."' and apptDay = '".$day."' and apptMonth = '".$month."' and apptYear = '".$year."' and reservation_aspara.roomId = '". $row3['roomId']."'");
          $row1 = mysql_fetch_array($rs1);
          if ($row1['count'] == 0)
            {
                $roomId = $row3['roomId'];
             $roomName=$row3['roomName'];
             $roomNumber=$row3['roomNumber'];
            

            }
      }

      if ($roomId != "")
      {
            mysql_query("Insert into reservation_aspara (name, contact, roomId, apptMonth, apptYear, apptDay, membershipId, email, time)
                                      values ('$name', '$telephone', '$roomId', '$month', '$year', '$day', '$member', '$email', '$time')");
                             $reservationID= mysql_query("select reservationId from reservation_aspara where roomId='".$roomId."' and time='".$time."' and apptDay='".$day."' and apptMonth='".$month."' and apptYear='".$year."'");         //echo  "Insert into reservation (name, contact, roomId, apptMonth, apptYear, apptDay, membershipId, email, time) values ('$name', '$telephone', '$roomId', '$month', '$year', '$day', '$member', '$email', '$time')";
            //echo "Registration successful. Your room id is ". $roomId;
        header("Location:confirmation_1.php?roomName=".$roomName."&roomId=".$roomId."&name=".$name."&roomNumber=".$roomNumber."&reservationId=".$reservationID);      }
      else
      {
              //echo "no room";
            header("Location:$location");
      }
      /*
      $rs1 = mysql_query("Select COUNT(*) as 'count' from reservation, room where time = '". $time ."' and apptDay = '".$day."' and apptMonth = '".$month."' and apptYear = '".$year."' and room.packageId = '". $package."' and reservation.roomId = room.roomId");
     //echo "Select COUNT(*) from reservation, room where time = '". $time ."' and apptDay = '".$day."' and apptMonth = '".$month."' and apptYear = '".$year."' and room.packageId = '". $package."' and reservation.roomId =  room.roomId";
     $rs2 = mysql_query("Select COUNT(*) as 'count' from room where packageId = '".$package."'");
     $row1 = mysql_fetch_array($rs1);
     $row2 = mysql_fetch_array($rs2);
     if ($row1['count'] == 0)
      {
            $rs3 = mysql_query("Select * from room where packageId = '".$package."'");
            $row3 = mysql_fetch_array($rs3);
          $roomid = $row3['roomId'];
          //$rs3 = mysql_query("Select * as 'count' from reservation, room where time = '". $time ."' and apptDay = '".$day."' and apptMonth = '".$month."' and apptYear = '".$year."' and room.packageId = '". $package."' and reservation.roomId = room.roomId");
          //
        }
      else if ($row1['count'] == $row2['count'])
     {
            $roomid = "";
      }
      else
      {

     } */
?>



Pls refer to the specific lines

$reservationID= mysql_query("select reservationId from reservation_aspara where roomId='".$roomId."' and time='".$time."' and apptDay='".$day."' and apptMonth='".$month."' and apptYear='".$year."'");
-------------------------------------------------------------------------------------
header("Location:confirmation_1.php?roomName=".$roomName."&roomId=".$roomId."&name=".$name."&roomNumber=".$roomNumber."&reservationId=".$reservationID);

----------------------------------------------------------------------------------
I have coded these lines to retrieve the reservation ID from the reservation_aspara table to and store it into a variable called $reservationID, before passing it into the header() tag to link it to the confirmation_1.php page.

Note that the reservationId is the primary key of the reservation_aspara table, and will be auto incremented whenever an entry is appended to the table.

However in the confirmation_1.php page, the reservation ID failed to appear, instead this message "Reservation Id: Resource id" appears. What does the Resource id denotes? And how to recode it so that the actual reservation id will appear?

This post has been edited by PHP_noob: 8 Jun, 2008 - 09:23 AM
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 8 Jun, 2008 - 09:34 AM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,987



Thanked 78 times

Dream Kudos: 1175
My Contributions


Am not positive here, but I think this may work out for you:

QUOTE
$reservationID= mysql_query("select reservationId as rid from reservation_aspara where roomId='".$roomId."' and time='".$time."' and apptDay='".$day."' and apptMonth='".$month."' and apptYear='".$year."'");
-------------------------------------------------------------------------------------
header("Location:confirmation_1.php?roomName=".$roomName."&roomId=".$roomId."&name=".$name."&roomNumber=".$roomNumber."&reservationId=".$reservationID['rid']);


<edit>
If that doesn't work you could try this:

QUOTE
$reservationID= mysql_query("select reservationId from reservation_aspara where roomId='".$roomId."' and time='".$time."' and apptDay='".$day."' and apptMonth='".$month."' and apptYear='".$year."'");
$row = mysql_fetch_assoc($reservationID);
-------------------------------------------------------------------------------------
header("Location:confirmation_1.php?roomName=".$roomName."&roomId=".$roomId."&name=".$name."&roomNumber=".$roomNumber."&reservationId=".$row['reservationID']);


For more information on mysql queries here is a link:
http://www.php.net/manual/en/function.mysql-query.php
</edit>

Tell me how that works out.

This post has been edited by BetaWar: 8 Jun, 2008 - 09:40 AM
User is offlineProfile CardPM

Go to the top of the page

silverblaze
post 8 Jun, 2008 - 12:06 PM
Post #3


D.I.C Head

**
Joined: 18 Jan, 2008
Posts: 51



Thanked 3 times
My Contributions


yes betawar is correct mysql_query will return only the resourceid. u need to use functoins like mysql_fetc_assoc, mysql_fetch_row(), mysql_fetch_array() etc to actually fetch the result.
more over these functions too return the result as an array. so if u need the reservationID. try this

CODE

$result= mysql_query("select reservationId from reservation_aspara where roomId='".$roomId."' and time='".$time."' and apptDay='".$day."' and apptMonth='".$month."' and apptYear='".$year."'");
$row = mysql_fetch_row($result);
$reservationID = $row['reservationId'];



i suppose thr is only one row with that conditions. else u need to use a while loop to get all the values.

hope it helps. plz let us knw.

takecare.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:39AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month