aniket_dj Posted March 28, 2007 Share Posted March 28, 2007 I get this error when running a PHP file in mozilla Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /opt/lampp/htdocs/initialpage.php:6) in /opt/lampp/htdocs/initialpage.php on line 7 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /opt/lampp/htdocs/initialpage.php:6) in /opt/lampp/htdocs/initialpage.php on line 7 //this is my session id 4effe596db6b5183402c61c3b81d1e19 The code for this is <html> <body> <br><br> <?php session_start(); mysql_connect("localhost", "root", "********") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //start session for storing user specific variables echo session_id(); $command=$_POST['command']; //echo "<form action='' method='post' name='main_form'>"; echo "<table border=1 cellpadding=5>"; echo "<tr><td>Start a fresh Problem Set</td>"; if($command=='Update') echo "<td><input type='submit' name='command' value='New'DISABLED/>"; else echo "<td><input type='submit' name='command' value='New'/>"; echo "</tr>"; echo "<tr><form action='' method='post' name='update'>"; echo "<td>Update an existing Problem Set </td>"; if($command=='Update') echo "<td><input type='submit' name='command' value='Update' Disabled/>"; else echo "<td><input type='submit' name='command' value='Update'/>"; echo "</form>"; echo "</tr>"; echo "</table>"; //echo "</form>"; echo "<br><br>"; if($command=='Update') { $query = "show databases"; $result = mysql_query($query) or die(mysql_error()); echo "<form action='tissues2.php' method='get' name='show_databases'>"; echo "<table cellpadding=5>"; echo "<tr><td>"; echo "Select a problem set"; echo "</td><td>"; echo "<select name='dbname'>"; echo "<option value='other' selected='selected'> </option>"; while($row = mysql_fetch_array($result)) { $temp=$row['Database']; echo "<option value=$temp>$temp</option>"; echo "<br>"; } echo "</select>"; echo "</td><td>"; echo "<input type='submit'/>"; echo "</td></tr>"; echo "</table>"; echo "</form>"; } ?> </body> </html> Can you please tell me where i am going wrong??? Link to comment https://forums.phpfreaks.com/topic/44687-solved-problem-with-php-sessions/ Share on other sites More sharing options...
papaface Posted March 28, 2007 Share Posted March 28, 2007 should be: <?php session_start(); ?> <html> <body> <br><br> <?php mysql_connect("localhost", "root", "********") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //start session for storing user specific variables echo session_id(); $command=$_POST['command']; //echo "<form action='' method='post' name='main_form'>"; echo "<table border=1 cellpadding=5>"; echo "<tr><td>Start a fresh Problem Set</td>"; if($command=='Update') echo "<td><input type='submit' name='command' value='New'DISABLED/>"; else echo "<td><input type='submit' name='command' value='New'/>"; echo "</tr>"; echo "<tr><form action='' method='post' name='update'>"; echo "<td>Update an existing Problem Set </td>"; if($command=='Update') echo "<td><input type='submit' name='command' value='Update' Disabled/>"; else echo "<td><input type='submit' name='command' value='Update'/>"; echo "</form>"; echo "</tr>"; echo "</table>"; //echo "</form>"; echo "<br><br>"; if($command=='Update') { $query = "show databases"; $result = mysql_query($query) or die(mysql_error()); echo "<form action='tissues2.php' method='get' name='show_databases'>"; echo "<table cellpadding=5>"; echo "<tr><td>"; echo "Select a problem set"; echo "</td><td>"; echo "<select name='dbname'>"; echo "<option value='other' selected='selected'> </option>"; while($row = mysql_fetch_array($result)) { $temp=$row['Database']; echo "<option value=$temp>$temp</option>"; echo "<br>"; } echo "</select>"; echo "</td><td>"; echo "<input type='submit'/>"; echo "</td></tr>"; echo "</table>"; echo "</form>"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/44687-solved-problem-with-php-sessions/#findComment-217006 Share on other sites More sharing options...
aniket_dj Posted March 28, 2007 Author Share Posted March 28, 2007 So not writing <?php session_start(); ?> before even the <html> tag was the problem?? Thanks. Link to comment https://forums.phpfreaks.com/topic/44687-solved-problem-with-php-sessions/#findComment-217026 Share on other sites More sharing options...
aniket_dj Posted March 28, 2007 Author Share Posted March 28, 2007 Thanks. It worked! Link to comment https://forums.phpfreaks.com/topic/44687-solved-problem-with-php-sessions/#findComment-217084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.