title: Troubleshooting "Warning: session_start(): Cannot send session cache limiter - headers already sent"
body: <p>i am getting    <strong>Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at</strong>  error</p>
  
  <p>If i submit form data to a different file for processing, it works. But if i submit form data to the same page, it gives this error. </p>
  
  <p>please suggst</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;
  &lt;title&gt;Welcome&lt;/title&gt;
  
  
  &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
  $(document).ready(function () { 
  
      $('#nav li').hover(
          function () {
              //show its submenu
              $('ul', this).slideDown(100);
  
          }, 
          function () {
              //hide its submenu
              $('ul', this).slideUp(100);         
          }
      );
  
  });
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
    &lt;tr&gt;
      &lt;td class="header"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td class="menu"&gt;&lt;table align="center" cellpadding="0" cellspacing="0" width="80%"&gt;
      &lt;tr&gt;
      &lt;td&gt;
  
      &lt;ul id="nav"&gt;
      &lt;li&gt;&lt;a href="#"&gt;Catalog&lt;/a&gt;
      &lt;ul&gt;&lt;li&gt;&lt;a href="#"&gt;Products&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Bulk Upload&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;div class="clear"&gt;&lt;/div&gt;
          &lt;/li&gt;
  
  
      &lt;li&gt;&lt;a href="#"&gt;Purchase  &lt;/a&gt;
  
      &lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Customer Service&lt;/a&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="#"&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;CS Panel&lt;/a&gt;&lt;/li&gt;
  
      &lt;/ul&gt;           
          &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;All Reports&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Configuration&lt;/a&gt;
      &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Look and Feel &lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href="#"&gt;Business Details&lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href="#"&gt;CS Details&lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href="#"&gt;Emaqil Template&lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href="#"&gt;Domain and Analytics&lt;/a&gt;&lt;/li&gt;
           &lt;li&gt;&lt;a href="#"&gt;Courier&lt;/a&gt;&lt;/li&gt;
           &lt;/ul&gt;
      &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Accounts&lt;/a&gt;
      &lt;ul&gt;&lt;li&gt;&lt;a href="#"&gt;Ledgers&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="#"&gt;Account Details&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
           &lt;div class="clear"&gt;&lt;/div&gt;&lt;/li&gt;
  
  &lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;table width="80%" border="0" align="center" cellpadding="0" cellspacing="0"&gt;
        &lt;tr&gt;
          &lt;td valign="top"&gt;&lt;table width="100%" border="0" cellspacing="0" cellpadding="2"&gt;
            &lt;tr&gt;
              &lt;td width="22%" height="327" valign="top"&gt;&lt;table width="100%" border="0" cellspacing="0" cellpadding="2"&gt;
                &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td height="45"&gt;&lt;strong&gt;-&amp;gt; Products&lt;/strong&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td height="61"&gt;&lt;strong&gt;-&amp;gt; Categories&lt;/strong&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td height="48"&gt;&lt;strong&gt;-&amp;gt; Sub Categories&lt;/strong&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;&lt;/td&gt;
              &lt;td width="78%" valign="top"&gt;&lt;table width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
                &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;
                    &lt;table width="90%" border="0" cellspacing="0" cellpadding="0"&gt;
                      &lt;tr&gt;
                        &lt;td width="26%"&gt;&amp;nbsp;&lt;/td&gt;
                        &lt;td width="74%"&gt;&lt;h2&gt;Manage Categories&lt;/h2&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                    &lt;/table&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td height="30"&gt;&amp;nbsp;
  
                  &lt;/td&gt;
                  &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;
  
  
  &lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                  &lt;td&gt;
                  &lt;table width="49%" align="center" cellpadding="0" cellspacing="0"&gt;
                  &lt;tr&gt;&lt;td&gt;
  
  
  
  
  &lt;?php
  
  
                  if (isset($_SESSION['error']))
  
                  {
  
                      echo "&lt;span id=\"error\"&gt;&lt;p&gt;" . $_SESSION['error'] . "&lt;/p&gt;&lt;/span&gt;";
  
                      unset($_SESSION['error']);
  
                  }
  
                  ?&gt;
  
                  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post" enctype="multipart/form-data"&gt;
  
                  &lt;p&gt;
                   &lt;label class="style4"&gt;Category Name&lt;/label&gt;
  
                     &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;input type="text" name="categoryname" /&gt;&lt;br /&gt;&lt;br /&gt;
  
                      &lt;label class="style4"&gt;Category Image&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  
                      &lt;input type="file" name="image" /&gt;&lt;br /&gt;
  
                      &lt;input type="hidden" name="MAX_FILE_SIZE" value="100000" /&gt;
  
                     &lt;br /&gt;
  &lt;br /&gt;
   &lt;input type="submit" id="submit" value="UPLOAD" /&gt;
  
                  &lt;/p&gt;
  
                  &lt;/form&gt;
  
  
  
  
                               &lt;?php
  
  session_start();
  
  require("includes/conn.php");
  
  
  function is_valid_type($file)
  
  {
  
      $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/png");
  
  
  
      if (in_array($file['type'], $valid_types))
  
          return 1;
  
      return 0;
  }
  
  function showContents($array)
  
  {
  
      echo "&lt;pre&gt;";
  
      print_r($array);
  
      echo "&lt;/pre&gt;";
  }
  
  
  $TARGET_PATH = "images/category";
  
  $cname = $_POST['categoryname'];
  
  $image = $_FILES['image'];
  
  $cname = mysql_real_escape_string($cname);
  
  $image['name'] = mysql_real_escape_string($image['name']);
  
  $TARGET_PATH .= $image['name'];
  
  if ( $cname == "" || $image['name'] == "" )
  
  {
  
      $_SESSION['error'] = "All fields are required";
  
      header("Location: managecategories.php");
  
      exit;
  
  }
  
  if (!is_valid_type($image))
  
  {
  
      $_SESSION['error'] = "You must upload a jpeg, gif, or bmp";
  
      header("Location: managecategories.php");
  
      exit;
  
  }
  
  
  
  
  if (file_exists($TARGET_PATH))
  
  {
  
      $_SESSION['error'] = "A file with that name already exists";
  
      header("Location: managecategories.php");
  
      exit;
  
  }
  
  
  if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
  
  {
  
  
  
      $sql = "insert into Categories (CategoryName, FileName) values ('$cname', '" . $image['name'] . "')";
  
      $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
  
    header("Location: mangaecategories.php");
  
      exit;
  
  }
  
  else
  
  {
  
  
  
  
  
      $_SESSION['error'] = "Could not upload file.  Check read/write persmissions on the directory";
  
      header("Location: mangagecategories.php");
  
      exit;
  
  }
  
  ?&gt; 
  </code></pre>
  
  <p>Here is the code for Display</p>
  
  <pre><code>&lt;?php  
                    require("includes/conn.php"); 
  
  
  
                  $sql = "select CategoryID, CategoryName, FileName, Status from Categories";
  
                  $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
  
  
  
                  while ($row = mysql_fetch_assoc($result))
  
                  {
  
                       echo "&lt;table border='0' cellpadding='10'&gt;";
  
  
                                          echo "&lt;tr&gt;&lt;td&gt;  &lt;/td&gt;&lt;td&gt;Category ID&lt;/td&gt;&lt;td&gt;Category Name&lt;/td&gt;&lt;td&gt;Status&lt;/td&gt;&lt;td&gt;Edit&lt;/td&gt;&lt;td&gt;Delete&lt;/td&gt;&lt;/tr&gt;";
  
                                          echo "&lt;tr&gt;&lt;td&gt; &lt;img src=\"images/" . $row['FileName'] . "\" alt=\"\" /&gt; &lt;/td&gt;";
                                          echo "&lt;td&gt;". $row['CategoryID'] . "&lt;/td&gt;";
                                              echo "&lt;td&gt;". $row['CategoryName'] . "&lt;/td&gt;";
                                              echo "&lt;td&gt;". $row['Status']. "&lt;/td&gt;";
                                              echo "&lt;td&gt; &lt;a href= 'edit.php?CategoryID=" .$row['id']. "'&gt; Edit &lt;/a&gt;&lt;/td&gt;";
                                              echo "&lt;td&gt; &lt;a href= 'delete.php?CategoryID=" .$row['id']. "'&gt; Edit &lt;/a&gt;&lt;/td&gt;";
                                           echo "&lt;/tr&gt; &lt;/table&gt;";
  
                  }
  
  
  
              ?&gt;
  </code></pre>
  
  <p>Nothing is happening here. Please suggest</p>