title: PHP Session Variable Not Passing with Header and Ob_Start Function
body: <p>This is my code:</p>
  
  <pre><code>&lt;?php
   ob_start();
   session_start();
   include("index.php");
   if (isset($_POST['user'],$_POST['pass'])):
       $con=mysqli_connect("connect info");
       if ( !$con ){
           die('Could not connect to Database: '.mysqli_error());}
   $pass=($_POST['pass']);
   $query0 = "SELECT * FROM user WHERE username = '" . $_POST['user'] ."' AND password = '" . $pass . "'";
   $resource0 = mysqli_query($con,$query0);
   if(!$resource0):
       die("Error conducting query. ".mysqli_error($con));
    endif;
    if(mysqli_num_rows($resource0) == 0){
          echo "Username not find";
          header("Location: /login.php");}
  
     $result0 = mysqli_fetch_row($resource0);
         $_SESSION['ID'] = $result0[0];
         $_SESSION['userType'] = $result0[3];
  
      if(!isset($_SESSION['ID'])):
          //header("Location: ...");
      else:
          header("Location: ....");
      endif;
  else: 
      if(isset($_POST['from'])):
          $_SESSION['from'] = $_POST['from'];
      endif;
  
      ?&gt;
  
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>This code takes a user's username and password information and stores and searching the database for the userID. Once is finds the information it stores in the session variable 'ID'. </p>
  
  <p><strong>PROBLEM</strong>: When the session 'ID' variable is passed to the next page it is not set. Surprisingly, this code without the ob_start function was working yesterday morning but wasn't working by the afternoon. I know it's not setting because two things: When I echo on the next page, nothing appears and because when I try to run a query with the session 'ID' variable I get a mysql error saying the query could not be conducted.</p>
  
  <p>This is the code on the next page that is not working. At first I thought, it might be something wrong with my query because I was getting this error: </p>
  
  <p>"Error conducting query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"</p>
  
  <p>But when I tried printing the session 'ID' variable nothing is printed. </p>
  
  <pre><code>&lt;?php session_start;
    // Create connection
    $con=mysqli_connect(connect info....);
  
   // Check connection
   if (mysqli_connect_errno($con))
   {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
  
   $query0 = "SELECT * FROM studentProfile WHERE sID = ".$_SESSION['ID'];
   $resource0 = mysqli_query($con,$query0);
   if(!$resource0):
  echo $_SESSION['ID'];
  die("Error conducting query. ".mysqli_error($con)); 
   endif;
  
   .......(rest of code)
  </code></pre>
  
  <p><strong>Solutions Already Tried</strong>: I have tried them all...session_write_close(), session_regenerate_id(true), session_commit(), ob_end_flush(). I have tried initially setting the session variable on the home page but once the functions are performed in the session 'ID' variable is no longer set at all.</p>
  
  <p>Please help! I have read all the forums I could find on this problem but nothing seems to work.</p>