Session Results Help Please

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 1805 Views - Last Post: 05 May 2009 - 08:17 AM Rate Topic: -----

#1 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Session Results Help Please

Posted 03 May 2009 - 08:44 AM

Hi I'm trying to create a booking system and below is my code. I want the result of the code to be posted to a page called results
  
<?php

// php login in here

if ($_GET["Monthci"] < 10) {				//Converts check in Month into format need by putting a 0 infront of single digits
$correctedmonthci = "0".$_GET["Monthci"];}
$correctedmonthci = $_GET["Monthci"];

if ($_GET["Dayci"] < 10) {					//Converts check in Day into format need by putting a 0 infront of single digits
$correcteddayci = "0".$_GET["Dayci"];}
$correcteddayci = $_GET["Dayci"];

if ($_GET["Monthco"] < 10) {				//Converts check out Month into format need by putting a 0 infront of single digits
$correctedmonthco = "0".$_GET["Monthco"];}
$correctedmonthco = $_GET["Monthco"];

if ($_GET["Dayco"] < 10) {					//Converts check out day into format need by putting a 0 infront of single digits
$correcteddayco = "0".$_GET["Dayco"];}
$correcteddayco = $_GET["Dayco"];



$checkindate = $_GET["Yearci"]."-".$correctedmonthci."-".$correcteddayci;	//Forms date into needed format
$checkoutdate = $_GET["Yearco"]."-".$correctedmonthco."-".$correcteddayco;	//Forms date into needed format

$days = round((strtotime("$checkoutdate") - strtotime("$checkindate"))/(60*60*24)); // Subtracts Checkin Date from Checkout date


$resort = $_GET['Resorts'];


$query = "SELECT * FROM hotel WHERE Resort = '$resort' ";		//Query for for finding hotels





 $result = mysql_query($query) 
	or die ("Couldn't execute query.");
	
	
	
echo "<form action = 'results.php' method='POST'>";

	
	
	while ($row = mysql_fetch_array($result)) {					//Creats Results table
	
	
		echo "Resort:		".$row['Resort']." <br/>";
		echo "Reviewer:	".$row['Reviewer']." <br/>";
		echo "Star Rating:		".$row['Star']."<br/>";
		echo "Website:	".$row['WebAddress']." <br/>";
		echo "<input type='radio' name = ".$row."d value =".$row['SingleRoom']."/> 
				Cost of a Single Room During Stay =  ".$row['SingleRoom']*$days." <br/>";
		echo "<input type='radio' name = ".$row."d value =".$row['DoubleRoom']."/> 
				Cost of a Double Room During Stay =  ".$row['DoubleRoom']*$days." <br/>";
		echo "<hr>";
		};


echo "<input type='submit' value = 'Proceed To Results' />";


?>
   



I need help on how to output the above result into another page and allow the user to see the page using session.

This post has been edited by inspectah: 03 May 2009 - 09:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Session Results Help Please

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 03 May 2009 - 09:10 AM

You need to start a session on each page, and on the first page you need to store your variables in session variables, then restore them on the second page.
Was This Post Helpful? 0
  • +
  • -

#3 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 03 May 2009 - 09:35 AM

I have this at the top of each page


<?php session_start(); 


?>





But don't know what to do next
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 03 May 2009 - 09:58 AM

Try this:

fileA.php
<?php
session_start();

$x = "some text";

$_SESSION['X'] = $x;
header("Location: fileB.php");
?>


fileB.php
<?php
session_start();

$y = $_SESSION['X'];
echo $y;
?>


Start with fileA.php

This post has been edited by CTphpnwb: 03 May 2009 - 10:01 AM

Was This Post Helpful? 0
  • +
  • -

#5 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 03 May 2009 - 10:34 AM

the thing I have a page allowing users to input their preferred date of booking which is below
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form action='file1.php' method='GET'>

<p>Select from the Drop down your preference of Location or places you wish to stay for your Holidays? </br>
  </br>
  <select name='Resorts'>
	<option value='Istanbul'> Istanbul </option>
	<option value='Bodrum'> Bodrum </option>
	<option value='Antalya'> Antalya </option>
	<option value='Izmir'> Izmir </option>
  </select>
  </br>
</p>
<p>
  Enter Start Date of your holidays!
  <select name= 'Dayci'>
	  <option value ='1'> 1st </option>
	  <option value ='2'> 2nd </option>
	  <option value ='3'> 3rd </option>
	  <option value ='4'> 4th </option>
	  <option value ='5'> 5th </option>
	  <option value ='6'> 6th </option>
	  <option value ='7'> 7th </option>
	  <option value ='8'> 8th </option>
	  <option value ='9'> 9th </option>
	  <option value ='10'> 10th </option>
	  <option value ='11'> 11th </option>
	  <option value ='12'> 12th </option>
	  <option value ='13'> 13th </option>
	  <option value ='14'> 14th </option>
	  <option value ='15'> 15th </option>
	  <option value ='16'> 16th </option>
	  <option value ='17'> 17th </option>
	  <option value ='18'> 18th </option>
	  <option value ='19'> 19th </option>
	  <option value ='20'> 20th </option>
	  <option value ='21'> 21st </option>
	  <option value ='22'> 22nd </option>
	  <option value ='23'> 23rd </option>
	  <option value ='24'> 24th </option>
	  <option value ='25'> 25th </option>
	  <option value ='26'> 26th </option>
	  <option value ='27'> 27th </option>
	  <option value ='28'> 28th </option>
	  <option value ='29'> 29th </option>
	  <option value ='30'> 30th </option>
	  <option value ='31'> 31st </option>
  </select>
	<select name= 'Monthci'>
	  <option value ='1'> January </option>
	  <option value ='2'> Febuary </option>
	  <option value ='3'> March </option>
	  <option value ='4'> April </option>
	  <option value ='5'> May </option>
	  <option value ='6'> June </option>
	  <option value ='7'> July </option>
	  <option value ='8'> August </option>
	  <option value ='9'> September </option>
	  <option value ='10'> October </option>
	  <option value ='11'> November </option>
	  <option value ='12'> December </option>
	</select>
	<select name='Yearci'>
	  <option value='2008'> 2008 </option>
	</select>
</p>
<p>Enter End Date of your holidays!
  <select name= 'Dayco'>
	<option value ='1'> 1st </option>
	<option value ='2'> 2nd </option>
	<option value ='3'> 3rd </option>
	<option value ='4'> 4th </option>
	<option value ='5'> 5th </option>
	<option value ='6'> 6th </option>
	<option value ='7'> 7th </option>
	<option value ='8'> 8th </option>
	<option value ='9'> 9th </option>
	<option value ='10'> 10th </option>
	<option value ='11'> 11th </option>
	<option value ='12'> 12th </option>
	<option value ='13'> 13th </option>
	<option value ='14'> 14th </option>
	<option value ='15'> 15th </option>
	<option value ='16'> 16th </option>
	<option value ='17'> 17th </option>
	<option value ='18'> 18th </option>
	<option value ='19'> 19th </option>
	<option value ='20'> 20th </option>
	<option value ='21'> 21st </option>
	<option value ='22'> 22nd </option>
	<option value ='23'> 23rd </option>
	<option value ='24'> 24th </option>
	<option value ='25'> 25th </option>
	<option value ='26'> 26th </option>
	<option value ='27'> 27th </option>
	<option value ='28'> 28th </option>
	<option value ='29'> 29th </option>
	<option value ='30'> 30th </option>
	<option value ='31'> 31st </option>
  </select>
  <select name= 'Monthco'>
	<option value ='1'> January </option>
	<option value ='2'> Febuary </option>
	<option value ='3'> March </option>
	<option value ='4'> April </option>
	<option value ='5'> May </option>
	<option value ='6'> June </option>
	<option value ='7'> July </option>
	<option value ='8'> August </option>
	<option value ='9'> September </option>
	<option value ='10'> October </option>
	<option value ='11'> November </option>
	<option value ='12'> December </option>
  </select>
  <select name='Yearco'>
	<option value='2008'> 2008 </option>
  </select>
</p>
<p>
  <input type='submit' value='Submit'>
  <br />

</body>
</html>



When they submit the php "File1" which the code i submitted earlier calculates the users input.


I want to know how to create the sessions so that this code results can be displayeed in a new page when the submit button is clicked
<?php

// php login in here

if ($_GET["Monthci"] < 10) {				//Converts check in Month into format need by putting a 0 infront of single digits
$correctedmonthci = "0".$_GET["Monthci"];}
$correctedmonthci = $_GET["Monthci"];

if ($_GET["Dayci"] < 10) {					//Converts check in Day into format need by putting a 0 infront of single digits
$correcteddayci = "0".$_GET["Dayci"];}
$correcteddayci = $_GET["Dayci"];

if ($_GET["Monthco"] < 10) {				//Converts check out Month into format need by putting a 0 infront of single digits
$correctedmonthco = "0".$_GET["Monthco"];}
$correctedmonthco = $_GET["Monthco"];

if ($_GET["Dayco"] < 10) {					//Converts check out day into format need by putting a 0 infront of single digits
$correcteddayco = "0".$_GET["Dayco"];}
$correcteddayco = $_GET["Dayco"];



$checkindate = $_GET["Yearci"]."-".$correctedmonthci."-".$correcteddayci;	//Forms date into needed format
$checkoutdate = $_GET["Yearco"]."-".$correctedmonthco."-".$correcteddayco;	//Forms date into needed format

$days = round((strtotime("$checkoutdate") - strtotime("$checkindate"))/(60*60*24)); // Subtracts Checkin Date from Checkout date


$resort = $_GET['Resorts'];


$query = "SELECT * FROM hotel WHERE Resort = '$resort' ";		//Query for for finding hotels





 $result = mysql_query($query)
	or die ("Couldn't execute query.");
   
   
   
echo "<form action = 'results.php' method='POST'>";

   
   
	while ($row = mysql_fetch_array($result)) {					//Creats Results table
   
   
		echo "Resort:		".$row['Resort']." <br/>";
		echo "Reviewer:	".$row['Reviewer']." <br/>";
		echo "Star Rating:		".$row['Star']."<br/>";
		echo "Website:	".$row['WebAddress']." <br/>";
		echo "<input type='radio' name = ".$row."d value =".$row['SingleRoom']."/>
				Cost of a Single Room During Stay =  ".$row['SingleRoom']*$days." <br/>";
		echo "<input type='radio' name = ".$row."d value =".$row['DoubleRoom']."/>
				Cost of a Double Room During Stay =  ".$row['DoubleRoom']*$days." <br/>";
		echo "<hr>";
		};


echo "<input type='submit' value = 'Proceed To Results' />";


?>




Thanks. Hope this will help you to rectify the problem
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 03 May 2009 - 11:59 AM

1) Read post #2.

2) Do the same thing with your code.
Was This Post Helpful? 0
  • +
  • -

#7 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 03 May 2009 - 01:55 PM

Should I include the variables in the first file.php or include it in the secod php (which is where all the code goes'
The this is file 1 get the file2 to calculates the users input and want the outcome of the result to display on the next page wich i'll name file3.
Help will be really appreciated thanks

This post has been edited by inspectah: 04 May 2009 - 12:19 PM

Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 03 May 2009 - 02:03 PM

1) :blink: What do includes have to do with session variables?
2) Why are you using strictly html in the first file? Html is static, so it has no variables. You need to set up your html (which could be generated by php) to post to a php file which will then process the information and generate new html.
3) If you do use php to generate html, then there might be some values that you want to pass from one page to another, even if other values are posted. That's where session variables come in, and that's what I've demonstrated in post 2.
Was This Post Helpful? 0
  • +
  • -

#9 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 04 May 2009 - 07:05 AM

How do you do that then. I'm a complete novice with PHP so don't understand what you saying

I'll be ahppy if you can break iy down a little bit. THe first code is the finder and the php code above is the process php. So how do i include the session and what should i do so that when the user access the process php on submit the results selected by the will display in a file called result.

Note I'm taliking about three php files here
1. the finder
2.the process
3.the result page
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 04 May 2009 - 07:45 AM

First, I see no reason to have more than two files. What you call the finder could be followed by one page with the process and results. In fact, the whole thing could be on one page!

Second, you really should be writing this using OOP. Even if you manage to finish it using procedural coding you're going to have great difficulty editing it when changes are needed later. At the very least you should be breaking things up into functions, but go all the way and learn about classes.

Third, don't use the word "include" unless you're talking about including files into your code. That's what it means in this context, so you're adding to the confusion by using it.
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 04 May 2009 - 08:27 AM

One more thing:

Computers are ideal for doing redundant tasks. Whenever you have code that is repetitive, there is very likely a better way to do it. Your html from post #5 for example, is a good candidate for being generated by php:
<?php
$opts = array("0","1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st");

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>';

echo "<form action='file1.php' method='GET'>
<p>Select from the Drop down your preference of Location or places you wish to stay for your Holidays? </br>
	</br>
	<select name='Resorts'>
	<option value='Istanbul'> Istanbul </option>
	<option value='Bodrum'> Bodrum </option>
	<option value='Antalya'> Antalya </option>
	<option value='Izmir'> Izmir </option>
	</select>
	</br>
</p>";

echo "<p>
	Enter Start Date of your holidays!
	<select name= 'Dayci'>";
for($i=1;$i<32;$i++) {
	echo "<option value ='".$i."'> ".$opts[$i]." </option>";
}
echo "</select>
	<select name= 'Monthci'>";
for($i=1;$i<13;$i++) {
	echo "<option value ='".$i."'> ".date("M",mktime(0,0,0,$i))." </option>";
}
echo "</select>
	<select name='Yearci'>
		<option value='2008'> 2008 </option>
	</select>
</p>
<p>Enter End Date of your holidays!
	<select name= 'Dayco'>";
for($i=1;$i<32;$i++) {
	echo "<option value ='".$i."'> ".$opts[$i]." </option>";
}
echo "</select>
	<select name= 'Monthco'>";
for($i=1;$i<13;$i++) {
	echo "<option value ='".$i."'> ".date("M",mktime(0,0,0,$i))." </option>";
}
echo "</select>
	<select name='Yearco'>
	<option value='2008'> 2008 </option>
	</select>
</p>
<p>
	<input type='submit' value='Submit'>
	<br />

</body>
</html>";

?>

See if you can shorten this further by putting the resorts in an array.

This post has been edited by CTphpnwb: 04 May 2009 - 08:29 AM

Was This Post Helpful? 1
  • +
  • -

#12 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 04 May 2009 - 09:18 AM

Thanks for above but again how do I include a section so that the date(which the user selects) will appear on a new page called result with the price of the using the process php in my first post.

Help will be really appraciated!

Note I tried your #2 post but still don't under stand how to eidt to make it fit in my website
Was This Post Helpful? 0
  • +
  • -

#13 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Session Results Help Please

Posted 04 May 2009 - 09:23 AM

When the user selects a date, it is sent to the next page (which could be the same php file) via GET.

Post #2 is just an example of how to transfer information that isn't sent via POST or GET.
Was This Post Helpful? 0
  • +
  • -

#14 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 04 May 2009 - 09:27 AM

OK I get but how do I store the result on the process page so the user can access it using the page called resullts.php

This post has been edited by inspectah: 04 May 2009 - 12:19 PM

Was This Post Helpful? 0
  • +
  • -

#15 inspectah  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 27-April 09

Re: Session Results Help Please

Posted 04 May 2009 - 09:47 AM

I have included this images if they helps

This post has been edited by inspectah: 04 May 2009 - 12:19 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2