943,175 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 159
  • PHP RSS
Sep 1st, 2010
0

passing variables

Expand Post »
well i have a form on the one page of my site that sends some variables accross using POST to another page. then some other things get calculated however the same variables from the first page need to be sent through to the next page.

and when i click a return button 'Link' to take me back to the previous page the variables are viewed as:

-----
Notice: Undefined index: daysOfMonth in C:\wamp\www\Universal Innovation\date_picked.php on line 2
-----

Please - how can i send variables accross from page to page and back again easily???

any help would be great
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010
Sep 1st, 2010
0
Re: passing variables
Can you post a snippet of your code?
Maybe your array with index 'daysOfMonth' is not in your form and was not passed with _POST?
Reputation Points: 14
Solved Threads: 9
Light Poster
Daiva is offline Offline
37 posts
since May 2009
Sep 1st, 2010
0
Re: passing variables
<select name="daysOfMonth" id="daysOfMonth" onchange="isValidDate()">
<option><?php if($day == 32){$day = 1; echo $day;}else{ echo $day + 1;} ?></option> <!--problem-->
<option>....</option>
<?php
for($i = 1; $i <= $days_in_month; $i++)
{
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
</div></td>
<td><label for="monthOfYear"></label>
<div align="center">
<select name="monthOfYear" id="monthOfYear" onchange="isValidDate()">
<option selected="selected"><?php echo $current_month; ?></option>
<option>........</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</div></td>
<td><label for="year"></label>
<select name="year" id="year" onchange="isValidDate()">
<option selected="selected"><?php echo $year; ?></option>
<option value="<?php echo $year + 1 ?>"><?php echo $year + 1 ?></option>
<option value="<?php echo $year + 2 ?>"><?php echo $year + 2 ?></option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label for="nights">
<div align="right">Number of nights:</div>
</label></td>
<td><select name="nights" id="nights" onchange="this.form">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select>

i get the date values from the menu and pass them to the next page where i display them:

-----------------

$dayArrive = $_POST["daysOfMonth"];
$month = $_POST["monthOfYear"];
$year = $_POST["year"];
$nights = $_POST["nights"];


<td><b>Arrival:</b><?php echo arriveDate($dayArrive, $month, $year) ?></td>
</tr>
<tr>
<td><b>Leaving:</b><?php echo departDate($dayArrive, $month, $year, $nights)?></td>
</tr>
<tr>
<td><b>Staying:</b><?php echo $nights . " " . $night ?></td>
</tr>

------------------

then i want to display them on the next page again, and when i hit the return link i need them to be passed pack to the previous page...

-----------------
<div id="Content" style="height:500px">
<table width="100%" border="0" cellpadding="6" style="margin-bottom:30px">
<tr>
<td align="center">Coastal View B+B<div id="returnPage"><a href="AvailableRooms.php" target="_self" >Return to previous page</a></div></td>
</tr>
<tr style="background-image:url(images/UIHeaderBreak.jpg); background-repeat:repeat-x">
<td>&nbsp;</td>
</tr>
<tr>
<td><b>Arrival:</b><?php echo arriveDate($dayArrive, $month, $year) ?><</td>
</tr>
<tr>
<td><b>Leaving:</b><?php echo departDate($dayArrive, $month, $year, $nights)?></td>
</tr>
<tr>
<td><b>Staying:</b><?php echo $nights . " " . $night ?></td>
</tr>
</table>
----------------------

does this help a bit more???
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010
Sep 1st, 2010
0
Re: passing variables
PHP variables do not exist between pages you will either have to use session variables, cookies or URL vairiable to pass the information back.

The easiest might be to put the values into the URL. You would have to build your link for the return as follows:

PHP Syntax (Toggle Plain Text)
  1. $href = "AvailableRooms.php?dayArrive=" . $dayArrive . "&month=" . $month . "&year=". $year . "&nights=" . $nights;

Then change you link to be more like this
PHP Syntax (Toggle Plain Text)
  1. <a href="<?php echo $href ?>" target="_self" >Return to previous page</a>

This will create a link that looks like this.
PHP Syntax (Toggle Plain Text)
  1. <a href="AvailableRooms.php?daysArrive=15&month=5&year=2011&nights=6" target="_self" >Return to previous page</a>


Now the information is being passed back to the previous page correctly. You will have to also retrieve this information from the corresponding $_GET array just like you did with the post

PHP Syntax (Toggle Plain Text)
  1. $dayArrive = $_GET["dayArrive"];
  2. $month = $_GET["month"];
  3. $year = $_GET["year"];
  4. $nights = $_GET["nights"];

You will also need to use isset($_GET["dayArrive"]) to test to see if you are getting data back or is this a first time display of the page.

You should look at the urlencode PHP function to make sure you do not have any issues passing information this way.
Reputation Points: 27
Solved Threads: 27
Junior Poster in Training
svilla is offline Offline
88 posts
since Aug 2010
Sep 1st, 2010
0
Re: passing variables
a little confussed about the isset()... how and where is that used? in an if() perhaps?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010
Sep 1st, 2010
0
Re: passing variables
Yes. like this...

PHP Syntax (Toggle Plain Text)
  1. if (isset($_GET['dayArrive'])) {
  2.  
  3. // Process return variables
  4.  
  5. $dayArrive = $_GET["dayArrive"];
  6. $month = $_GET["month"];
  7. $year = $_GET["year"];
  8. $nights = $_GET["nights"];
  9.  
  10. } else {
  11.  
  12. // First time processing (if any)
  13.  
  14. }
Reputation Points: 27
Solved Threads: 27
Junior Poster in Training
svilla is offline Offline
88 posts
since Aug 2010
Sep 1st, 2010
0
Re: passing variables
sweet well now it seems to be giving me this error:

Notice: Undefined index: daysOfMonth in C:\wamp\www\Universal Innovation\AvailableRooms.php on line 35

Notice: Undefined index: monthOfYear in C:\wamp\www\Universal Innovation\AvailableRooms.php on line 36

and only for those two variables...???
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010
Sep 1st, 2010
0
Re: passing variables
You need to make sure that the variable names match between what is on the URL and the $_GET variable. If you are passing dayArrive on the URL then you have to use $_GET['dayArrive'] to access it.
Reputation Points: 27
Solved Threads: 27
Junior Poster in Training
svilla is offline Offline
88 posts
since Aug 2010
Sep 2nd, 2010
0
Re: passing variables
you legend....

all sorted

shot
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
gchurch is offline Offline
52 posts
since Aug 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Multiple search fields results
Next Thread in PHP Forum Timeline: how to delete a table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC