2 Replies - 916 Views - Last Post: 08 June 2008 - 01:06 PM Rate Topic: -----

#1 PHP_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-June 08

Need help with database retrieval in PHP codes

Posted 08 June 2008 - 10:21 AM

Hi there pls refer to the following codes

<?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: 08 June 2008 - 10:23 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with database retrieval in PHP codes

#2 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,134
  • Joined: 07-September 06

Re: Need help with database retrieval in PHP codes

Posted 08 June 2008 - 10:34 AM

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/m...mysql-query.php
</edit>

Tell me how that works out.

This post has been edited by BetaWar: 08 June 2008 - 10:40 AM

Was This Post Helpful? 0
  • +
  • -

#3 silverblaze  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 69
  • Joined: 18-January 08

Re: Need help with database retrieval in PHP codes

Posted 08 June 2008 - 01:06 PM

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

$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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1