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

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?

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

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:

$href = "AvailableRooms.php?dayArrive=" . $dayArrive . "&month=" . $month . "&year=". $year . "&nights=" . $nights;

Then change you link to be more like this

<a href="<?php echo $href ?>" target="_self" >Return to previous page</a>

This will create a link that looks like this.

<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

$dayArrive = $_GET["dayArrive"];
$month = $_GET["month"];
$year = $_GET["year"];
$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.

a little confussed about the isset()... how and where is that used? in an if() perhaps?

Yes. like this...

if (isset($_GET['dayArrive'])) {

// Process return variables

   $dayArrive = $_GET["dayArrive"];
   $month = $_GET["month"];
   $year = $_GET["year"];
   $nights = $_GET["nights"];

} else {

// First time processing (if any)

}

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

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 to access it.

you legend....

all sorted

shot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.