PHP Session Start - why am I getting header errors?
Posted: Fri Jul 24, 2015 8:33 am
When I wrote this locally, I didn't get any errors.Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/premiers/public_html/beta/ajax_length.php:2) in /home/premiers/public_html/beta/ajax_length.php on line 3
Length
The user selects a value from a dropdown. That then activates a second dropdown via an Ajax call. But now, that second dropdown also causes the above warning to show.
Each Ajax dropdown is via it's own *.php file, so it has to have the session_start in it to find, and keep the session going and to find the relevant entries in the database based on the previous dropdown.
This is the file where the error is coming from:
Code: Select all
<?php
session_start();
unset($_SESSION['length']);
include "dbconn.php";
$primaryid = isset($_SESSION['primaryid']) ? $_SESSION['primaryid'] : null;
$depth = isset($_GET['depth']) ? $_GET['depth'] : null;
if ($depth == "0") { $depth = "";}
$_SESSION['depth'] = $depth;
$depth = $_SESSION['depth'];
$resultlength = mysql_query ("SELECT length FROM products WHERE primaryid = '$primaryid' AND depth = '$depth' GROUP BY length ORDER by length");
$num_rows = mysql_num_rows($resultlength);
if ($num_rows != 0)
{
echo "<div class='product_dimension_inner'>Length</div>
<div class='product_dimension_inner'><select id='length' name='length' onChange=\"checkthickness(this.value);\" class='selectpremier'>
<option value='0'>Choose</option>";
while ($rowlength = mysql_fetch_object($resultlength))
{
echo "<option value='$rowlength->length'>$rowlength->length\"</option>";
}
echo "</select></div>";
}
?>