php从表单设置会话变量

This is my main report page where I am sending session variables to another php page. I am running into issues when I try and post the form data to the session variables because then the query returns nothing. I have been searching and tinkering for a few days now but no results.

<!DOCTYPE html>
    <?php
      session_start();
     /* this works when the session variables are static*/
     $_SESSION["date"] = '2012-05-01'; 
     $_SESSION["ServiceOrders"] ='Network Error';  
     /* when I try and post the form values the query returns nothing
      $_SESSION["date"] = $_POST['sdate']; 
      $_SESSION["ServiceOrders"] =   $_POST['ServiceOrders']; 
     */

    ?>
    <html>

  <head>   
      <link rel='stylesheet' type='text/css' href='styles.css' />
      <link rel="stylesheet" href="grid.css" type="text/css" />
      <link rel="stylesheet" href="backgroundcss.css" type="text/css" />
<style>
form { width: 700px; }
label { float: left; width: 100px; }
input[type=text] { float: left; width: 200px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }

</style>

    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script type='text/javascript' src='menu_jquery.js'></script>
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>    

<script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });

 $(function() {
     $("#refresh").on("click", function() {
        $("#mydiv").load("http://***.***.***.***/ServiceOReport.php");
        return false;
    })
  })

</script>

  </script>
  </head>

  <body  class="container">
  <br>
<div id='menu'>
<ul>
   <li class='active'><a href='LineChart.php'><span>Home</span></a></li>
   <li class='has-sub'><a href='#'><span>Contacts</span></a>
      <ul>
         <li><a href='allrows.php'><span>Inbound Calls Codes</span></a></li>
         <li class='last'><a href='#'><span>Contact Free Form</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Service Orders</span></a>
      <ul>
         <li><a href='#'><span>Company Service Orders</span></a></li>
         <li class='last'><a href='#'><span>Vendor Service Orders</span></a></li>
      </ul>
   </li>
   <li class='last'><a href='#'><span>Ad Hoc Report Builder</span></a></li>
</ul>

</div>
<br>
<form action="ServiceOReport.php" method="post">
<select name="ServiceOrders">
  <option value="Network Error">Network Error</option>
  <option value="Reverse Rotation Detected">Computer Failure</option>
  <option value="Cover Off">Misc</option>
  <input type="text" name="sdate"id="datepicker" >
  <input type="submit" id ="refresh" value=" Submit "/><br />
</select>
</form>

<div id="mydiv" class="grid_12 omega scroll">

</div>  

<div class="grid_12 ">  
    <div   id="TopBorder"  class="grid_12">
        <footer class="mainFooter">
            <p>Copyright &copy; 2014 <a href="http://test.com">Test</a></p>
        </footer>
    </div>
</div>  

  </body>
</html>

This is my ServiceOReport.php page where I am taking the session variables and executing them in the query.

<html>
  <head>   
      <link rel='stylesheet' type='text/css' href='styles.css' />
      <link rel="stylesheet" href="grid.css" type="text/css" />
      <link rel="stylesheet" href="backgroundcss.css" type="text/css" />
 </head>      

  <body  class="container">
        <?php
 session_start();

        // Make a MySQL Connection
    mysql_connect("localhost", "****", "********") or die(mysql_error());
    mysql_select_db("Test_DB") or die(mysql_error());

    $ServiceOrders= $_SESSION["ServiceOrders"];
    $string=$_SESSION["date"];
    $timestamp = strtotime($string);
    $correctedDate = date("Y-m-d H:i:s", $timestamp);

    $result = mysql_query("Select EquipmentID,StreetNumber,StreetName,City,ZipCode,ZipPlusFour,CreatedDate,ServiceOrderdesc 
                            From CSS_ServiceOrders  
                            Where ServiceOrderdesc = '$ServiceOrders' and CreatedDate > '$correctedDate'
                            order by CreatedDate,StreetName,StreetNumber;") 
    or die(mysql_error());  

    echo '<table class="bordered">
<thead>
    <tr>
        <th scope="col">EquipmentID</th>
        <th scope="col">ZipPlusFour</th>        
        <th scope="col">StreetNumber</th>
        <th scope="col">StreetName</th>
        <th scope="col">City</th>       
        <th scope="col">ZipCode</th>                    
        <th scope="col">CreatedDate</th>
        <th scope="col">ServiceOrderdesc</th>   
    </tr>
</thead>
<tbody>';


    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {

        echo "<tr><td>"; 
        echo $row['EquipmentID'];
        echo "</td><td>"; 
        echo $row['ZipPlusFour'];
        echo "</td><td>";       
        echo $row['StreetNumber'];
        echo "</td><td>";       
        echo $row['StreetName'];
        echo "</td><td>";       
        echo $row['City'];
        echo "</td><td>";       
        echo $row['ZipCode'];
        echo "</td><td>";       
        echo $row['CreatedDate'];
        echo "</td><td>"; 
        echo $row['ServiceOrderdesc'];
        echo "</td></tr>"; 

    } 

    echo "</tbody></table>";
?>
</body>
</html>

You must put session_start() at the top of the page before any output.

<?php
    session_start();
?>
<!DOCTYPE html>
<?php    

and

<?php
    session_start();
?>
<html>
  <head>   
      <link rel='stylesheet' type='text/css' href='styles.css' />
      <link rel="stylesheet" href="grid.css" type="text/css" />
      <link rel="stylesheet" href="backgroundcss.css" type="text/css" />
 </head>      

  <body  class="container">
        <?php

As @John said you need to put session_start() at the beginning of the file the main reason for this is as soon as the interpreter sees any non PHP code or echo, it sends out the headers. It has to otherwise it cant send anything but once the headers are sent they cant be resent.

PHP sessions rely heavily on headers, it has to to set and make the page send over cookie details so it knows which session it has to look up.

Make sure there are no spaces or empty lines before you php tag and that there are no echos before your session_start() command. These are hard to debug, easy to make a mistake with so I always mention them to people.