Can anyone help me with this error?
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\guestbook.php:1) in C:\xampp\htdocs\guestbook.php on line 1
I've eliminated all tabs, spaces before and after my line 1, but that error message still displays.
Code:<TITLE>Comments</TITLE><?php session_start(); if(!isset($_SESSION['nname'])) { $_SESSION['nname'] = 'Anonymous'; } if (!isset($_GET['command'])) { echo "Welcome " . $_SESSION['nname'] . "<br>"; ?> <a href ="?command=add">Add Post</a> <a href ="?command=display">Display Post</a> <a href ="?command=login">Set Nickname</a> <?php } else { if ($_GET['command'] == 'add'){ add_comment(); } elseif ($_GET['command'] == 'adding'){ adding(); } elseif ($_GET['command'] == 'display'){ display_comments(); } elseif ($_GET['command'] == 'login'){ set_name(); } elseif($_GET['command']=='logging'){ logging(); } } function add_comment() { ?> <form action = "?command=adding" method = POST> <textarea rows= 5 name = "comment">Insert your comments here...</textarea> <input type = "submit" value = "Post"> </form> <?php } function adding() { $con1 = mysql_connect("localhost", "root", "password"); mysql_select_db("guestbook",$con1); mysql_query("INSERT INTO comments (userid, comment, when_posted) VALUES (".$_SESSION['nname'].",".$_POST['comment'].", Now()" ); ?> <br> <a href = "?command=display">View Comments</a> <?php mysql_close($con1); } function set_name() { ?> <form action = "?command=logging" method = POST> Set your nickname: <input type = "text" name = "nname"> <br><input type = "submit" value = "Set"> </form> <?php } function display_comments() { $con = mysql_connect("localhost", "root", "password"); mysql_select_db("guestbook",$con); $results = mysql_query("SELECT * FROM comments ORDER BY id DESC"); echo "<TABLE BORDER = 1>"; while($row = mysql_fetch_array($results)) { echo "<TR>"; echo "<TD BGCOLOR = PINK>" . $row['userid'] . "</TD>"; echo "<TD BGCOLOR = YELLOW>" . $row['comment'] . "</TD>"; echo "<TD BGCOLOR = SKYBLUE>" . $row['when_posted'] . "</TD>"; echo "</TR>"; } echo "</TABLE>"; mysql_close($con); } function logging() { $_SESSION['nname'] = $_POST['nname']; echo "Hello " . $_SESSION['nname']; ?> <a href = "guestbook.php">Back</a> <?php } ?>




Reply With Quote