php - Session not passing POSTed data to second script - please advise -


tried asking this, marked duplicate suggestion. employed suggestions still not seem performing desired result. read following , advise going wrong?

i attempting use sessions pass user selected data script (allotment.php) subsequent script (allotmentreport.php) wherein used in query qualifier (e.g. ...where tablecolumndata=session variable...). not getting error allotment.php upon selecting option , clicking submit data fails pass allotmentreport.php , returns error undefined variable.

is , line after correct? there missing otherwise? $tourselect=(isset($_post['submit']));

update final , corrected code displayed below future users seeking working example , easy read solution:

    <?php      session_start();     $host="localhost";     $username="hidden";     $password="hidden";     $dbname="bookings2015";     $con = mysql_connect($host, $username, $password, $dbname);     if (!$con)     {     die ('damn thing wont connect mysql server: maybe retarded '. mysql_error());     } mysql_select_db($dbname, $con); ?> <!doctype html> <html> <?php include 'c:\xampp\htdocs\phpproject1\head.php';  include 'config\menu.php'; ?>  <div id="dataentry"> <div id="submit"> <?php echo "which tour check availability?&nbsp;&nbsp;&nbsp;";?> <br /> <br /> </br> </br> <form method="post" action="allotment_report.php"> <select name='tourcode'> <?php $tourselection = "select distinct tourcode toursanddates order tourcode"; $result = mysql_query($tourselection); while ($row = mysql_fetch_array($result)) {     echo "<option value='" . $row['tourcode'] . "'>" . $row['tourcode'] . "</option>"; } ?> </select> <input type="submit" name="tourselected" value="submit"> </form> <?php ?> </div> </div> <div id="demographicborder"> <?php  include 'footer.php';?>              </div> </div>     </body> </html> </form> </form> </div> </div> </div> </body> </html> 

and here allotment_report.php code

        <?php          session_start();         $host="localhost";         $username="stillhidden";         $password="stillhidden";         $dbname="bookings2015";         $con = mysql_connect($host, $username, $password, $dbname);         if (!$con)         {         die ('damn thing wont connect mysql server: maybe retarded '. mysql_error());         }     mysql_select_db($dbname, $con);     include 'c:\xampp\htdocs\phpproject1\head.php';      include 'config\menu.php';     ?>      <br />     <br />     <?php  //table header: echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><u>tour availability</u>";     echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">     <tr>         <td align=:"left"><b>tour:</b></td>         <td align=:"left"><b>start date:</b></td>         <td align=:"left"><b>seats avail:</b></td>         <td align=:"left"><b>rooms avail:</b></td>     </tr>     ';     if(isset($_post['tourcode'])){             $tour=$_post['tourcode'];         }     $status="ok";     $ar="select tourcode, date_format (tourstart, '%m%d%y') tourstart, seatsavail, roomsavail toursanddates tourcode='$tour' , status='$status' order tourcode, tourstart asc";      $result=mysql_query($ar);     $num_results = mysql_num_rows($result);     while($row = mysql_fetch_assoc($result)){     //display allotments fetched in above query     echo '<tr>             <td align=:"left">' . $row['tourcode'] . '</td>             <td align=:"left">' . $row['tourstart'] . '</td>             <td align=:"left">' . $row['seatsavail'] . '</td>             <td align=:"left">' . $row['roomsavail'] . '</td>              </tr>             ';     }     echo '</table>';     //echo "</strong>tour:&nbsp;&nbsp;".($row['tourcode']);     //echo "</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start date: ".($row['tourstart']);         ?>     <br />         <?php     echo "<br />";     echo "</p>";     ?>     </br>     </br>     </div>     </form>      </div>     <div id="demographicborder">     <?php include 'footer.php';     ?>                   </div>     </div>         </body>     </html>     </form>     </form>     </div>     </div>     </div>     </body>     </div>     </body> 

<?php     //contained within allotment.php     $tourselect=(isset($_post['tourselected']));     $_session['tourselected']=$tourselect; ?> 

it looks expecting $_session['tourselected'] set on allotment.php when user loads opens page first time. not case. $_post data attached http request. when load alloment.php first time, browser doesn't send $_post data it. explain why $_session['tourselected'] unset when second script.

that said, if goal send data form built in alloment.php alloment_report.php you shouldn't using sessions @ all. of can done $_post.

consider following code:

 <!--alloment.php-->     <form method="post" action="alloment_report.php">         <select name='tourcode'>             <?php              //assume $options contains stuff pulled database.             foreach($options $option) {                 echo "<option value='" . $option . "'>" . $option . "</option>";             }             ?>         </select>         <input type="submit" name="tourselected" value="submit">     </form> 

when user completes form, , clicks submit, alloment_report.php (specified action="alloment_report") gets data sent form on $_post (specified method="post").

<!--alloment_report.php-->     <?php     if(isset($_post['tourcode'])){         echo "yay! tour has been selected!";     }     ?> 

Comments