simpli Posted April 12, 2009 Share Posted April 12, 2009 Hi, before I go any further I wanna say I read the header error primer. This isn't my first time dealing with header error but I haven't been able to clear this one and I am so close to a deadline. Also I am using a login library (phpliblogin) and I don't know if it's messing with my code. The error message I have is session_register() [<a href='function.session-register'>function.session-register</a>]: Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/htdocs/choice_round_1.php:1) in /Applications/MAMP/htdocs/php_lib_login_includes/login.inc.php on line 247 Now I checked the code in my script and there is no invisible character and nothing that is output before i call the header. Can anyone help me? This is the whole code in my php file. <?php // standard stuff php_lib_login needs to have include('php_lib_login_includes/login.inc.php'); $nombre_joueurs = 10; if(lib_login_valid_user()) { // call this to protect the page $user = lib_login_protect_page(); //Validation of players $error_validation=array(); //initialize $error to empty array //If we get here as a result of the submit button having been pushed: We are going to validate the data if(isset($_POST['submit'])){ global $nombre_joueurs; $nbjoueurs = $nombre_joueurs; $arrayPlayers[] = array(); $arrayCount = array(); for ($i=1; $i <= $nbjoueurs; $i++) { if(trim($_POST['player_' . $i])=='') { $error_validation['player_' . $i] = "Votre joueur #" . $i . " n'a pas ete choisi!<br />"; } else{ //If player fields are not empty we place the 10 chosen players in an array that will be used to validate the duplicates $arrayPlayers[$i-1] = $_POST['player_' . $i]; } } //Validation of matchups if(!isset($_POST['m_1vs8East'])){ $error_validation['m_1vs8East'] .="Vous devez choisir un gagnant pour l'affrontement 1 Vs 8 Est!<br />"; } if(!isset($_POST['m_2vs7East'])){ $error_validation['m_2vs7East'] ="Vous devez choisir un gagnant pour l'affrontement 2 Vs 7 Est!<br />"; } if(!isset($_POST['m_3vs6East'])){ $error_validation['m_3vs6East'] ="Vous devez choisir un gagnant pour l'affrontement 3 Vs 6 Est!<br />"; } if(!isset($_POST['m_4vs5East'])){ $error_validation['m_4vs5East'] ="Vous devez choisir un gagnant pour l'affrontement 4 Vs 5 Est!<br />"; } if(!isset($_POST['m_1vs8West'])){ $error_validation['m_1vs8West'] ="Vous devez choisir un gagnant pour l'affrontement 1 Vs 8 Ouest!<br />"; } if(!isset($_POST['m_2vs7West'])){ $error_validation['m_2vs7West'] ="Vous devez choisir un gagnant pour l'affrontement 2 Vs 7 Ouest!<br />"; } if(!isset($_POST['m_3vs6West'])){ $error_validation['m_3vs6West'] ="Vous devez choisir un gagnant pour l'affrontement 3 Vs 6 Ouest!<br />"; } if(!isset($_POST['m_4vs5West'])){ $error_validation['m_4vs5West'] ="Vous devez choisir un gagnant pour l'affrontement 4 Vs 5 Ouest!<br />"; } $arrayCount = array_count_values($arrayPlayers); foreach ($arrayCount as $key => $arrayCount) { if($arrayCount.$key >1){ $error_validation[$key] = $key . " ne peut etre choisi plus d'une fois <br />"; } } //There are no errors we can write to database if(empty($error_validation)){ //If data has been validated correctly we open connection to the database and we start writing to it. include('config.php'); include('opendb.php'); addmatchups($conn); addfinalist($conn); addChampion($conn); addGoalie($conn); addPlayers($conn); mysql_close($conn); //After writing to table, redirect to results page header("Location: http://localhost:8003/showresults.php"); } } //if $error = success: We come here as a result of a successful account creation and we will show no error message proceed_show_form($error_validation); } function proceed_show_form($error_v){ //We come here if the form is showed for the first time (not a result of the submit button //We do all this only if the user has been authenticated //html page header info print <<<htmldebut1 <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <html><head> <META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8"> <META HTTP-EQUIV="Content-Language" CONTENT="fr-CA"> <title>Page des poolers</title> htmldebut1; include('textmenu.css'); include('validate.js'); include('optionsmenu.php'); print <<<htmldebut2 </head> <body> <b>Entrez vos choix pour la première ronde</b> htmldebut2; // Connects to the pool database include('config.php'); include('opendb.php'); retrieveMatchups(1,'East',$conn,$error_v); retrieveMatchups(1,'West',$conn,$error_v); chooseFinalist('East','one',$conn); chooseFinalist('West','two',$conn); chooseChampion($conn); chooseGoaltender($conn); choosePlayers($error_v); mysql_close($conn); echo '<input type="submit" name="submit" value="Soumettre vos choix">'; if(!empty($error_v)){ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo implode( $error_v); echo '</fieldset>'; } } //End of the form echo '</form></br> </body></html> ' ?> <?php function retrieveMatchups($round, $conference, $conn,$error){ //We retrieve the matchup list for the Eastern conference $sql_matchup =<<<SQL SELECT * FROM matchup where matchup_name like '%$conference' and round=$round order by matchup_number SQL; $lconn = $conn; $result = mysql_query($sql_matchup ,$conn); if(!$result) die("Query Failed."); //Shows Eastern conference matchups echo '</br>'; echo '<fieldset>'; echo '<legend>'. $conference . '</legend>'. "\n"; while($row =mysql_fetch_assoc($result)) { echo '<label for="' . 'm_' . $row["matchup_name"] . '_1"'. (isset($error['m_' . $row["matchup_name"]]) ? ' class="error"' :'') .'>' . '<input name="' .'m_' . $row["matchup_name"] .'" type="radio" id="' .'m_' . $row["matchup_name"] . '_1"' . ' value="' . $row["team1"] . '"'; if(isset($_POST['m_' . $row["matchup_name"]])) echo ($_POST['m_' . $row["matchup_name"]] == $row["team1"]? ' checked' : ''); echo '">' . $row["team1"] . '</label>' . "\n"; echo '<label for="' . 'm_' . $row["matchup_name"] . '_2"'. (isset($error['m_' . $row["matchup_name"]]) ? ' class="error"' :'') .'>' . '<input name="' .'m_' . $row["matchup_name"] .'" type="radio" id="' .'m_' . $row["matchup_name"] . '_2"' . ' value="' . $row["team2"] . '"'; if(isset($_POST['m_' . $row["matchup_name"]])) echo ($_POST['m_' . $row["matchup_name"]] == $row["team2"]? ' checked' : ''); echo '">' . $row["team2"] . '</label>' . "\n"; echo ' <select name="'. 'nbmatch_'.$row["matchup_name"] . '">'; echo '<option selected="selected">4<option>5<option>6<option>7</select>'; echo '</br>' . "\n"; } echo '</fieldset>'; } function chooseFinalist($conference, $class,$conn) { //choice of Eastern finalist //We retrieve the matchup list for the Western conference $sql_finalist =<<<SQL SELECT * FROM playoff_teams WHERE conference = '$conference' ORDER BY rank SQL; $lconn = $conn; $result = mysql_query($sql_finalist ,$lconn); if(!$result) die("Query Failed."); echo '<fieldset class="' . $class .'" style="width:200px">' . "\n"; echo '<legend>Finaliste ' . ($conference == "West" ? "Ouest" : "Est"). '</legend>' . "\n"; echo ' <select name="'. 'finalist' . $conference . '">' . "\n"; //Lists all the potential finalists of the specied conference while($row =mysql_fetch_assoc($result)) { echo '<option'; if(isset($_POST['finalist' . $conference])){ if($_POST['finalist' . $conference] == trim($row["name"])) echo ' selected="selected"'; } echo '>' . trim($row["name"]) . "\n"; } echo '</select>'; echo '</fieldset>'; echo '</br>' . "\n"; } function chooseChampion($conn) { //Choice of Stanley cup champion $lconn = $conn; //We retrieve the matchup list for the Western conference $sql_champion =<<<SQL SELECT * FROM playoff_teams ORDER BY rank, conference SQL; $result = mysql_query($sql_champion ,$lconn); if(!$result) die("Query Failed."); echo '<fieldset class="three" style="width:100">'; echo '<legend>Champion</legend>'; echo ' <select name="champion">' . "\n"; //List of all the potential Stanley cup champions while($row =mysql_fetch_assoc($result)) { echo '<option'; if(isset($_POST['champion'])){ if($_POST['champion'] == trim($row["name"])) echo ' selected="selected"'; } echo '>' . trim($row["name"]) . "\n"; } echo '</select>'; echo '</fieldset>'; echo '</br>' . "\n"; } function chooseGoaltender($conn) { //Choice of goaltender //We retrieve the matchup list for the Western conference $sql_goalie =<<<SQL SELECT goalies.name FROM goalies, playoff_teams WHERE goalies.team = playoff_teams.short_name SQL; $lconn = $conn; $result = mysql_query($sql_goalie ,$lconn); if(!$result) die("Query Failed."); echo '<fieldset class="four">'; echo '<legend>Votre gardien</legend>'; echo ' <select name="goalie">' . "\n"; //List of all the potential Stanley cup champions while($row =mysql_fetch_assoc($result)) { echo '<option'; if(isset($_POST['goalie'])){ if($_POST['goalie'] == trim($row["name"])) echo ' selected="selected"'; } echo '>' . trim($row["name"]) . "\n"; } echo '</select>'; echo '</fieldset>'; echo '</br>'; } function addmatchups($conn) { $round = 1; global $user; $luser = $user; $lconn = $conn; $luser = mysql_real_escape_string($user); //We retrieve the matchup list for the Western conference $sql_matchup =<<<SQL SELECT 'username' from matchup_choices where matchup_choices.username ='$luser'; SQL; $result = mysql_query($sql_matchup ,$lconn); $num_rows = mysql_num_rows($result); //The user of which we are trying to write the matchup does not exist so we can add it if($num_rows == 0){ //We add the matchups //Eastern conference $choice_1vs8East = mysql_real_escape_string($_POST['m_1vs8East']); $number_matches = mysql_real_escape_string($_POST['nbmatch_1vs8East']); addMatchupLines($luser, $round, '1vs8East', $choice_1vs8East, $number_matches, $lconn); $choice_2vs7East = mysql_real_escape_string($_POST['m_2vs7East']); $number_matches = mysql_real_escape_string($_POST['nbmatch_2vs7East']); addMatchupLines($luser, $round, '2vs7East', $choice_2vs7East, $number_matches, $lconn); $choice_3vs6East = mysql_real_escape_string($_POST['m_3vs6East']); $number_matches = mysql_real_escape_string($_POST['nbmatch_3vs6East']); addMatchupLines($luser, $round, '3vs6East', $choice_3vs6East, $number_matches, $lconn); $choice_4vs5East = mysql_real_escape_string($_POST['m_4vs5East']); $number_matches = mysql_real_escape_string($_POST['nbmatch_4vs5East']); addMatchupLines($luser, $round, '4vs5East', $choice_4vs5East, $number_matches, $lconn); //Western conference $choice_1vs8West = mysql_real_escape_string($_POST['m_1vs8West']); $number_matches = mysql_real_escape_string($_POST['nbmatch_1vs8West']); addMatchupLines($luser, $round, '1vs8West', $choice_1vs8West, $number_matches, $lconn); $choice_2vs7West = mysql_real_escape_string($_POST['m_2vs7West']); $number_matches = mysql_real_escape_string($_POST['nbmatch_2vs7West']); addMatchupLines($luser, $round, '2vs7West', $choice_2vs7West, $number_matches, $lconn); $choice_3vs6West = mysql_real_escape_string($_POST['m_3vs6West']); $number_matches = mysql_real_escape_string($_POST['nbmatch_3vs6West']); addMatchupLines($luser, $round, '3vs6West', $choice_3vs6West, $number_matches, $lconn); $choice_4vs5West = mysql_real_escape_string($_POST['m_4vs5West']); $number_matches = mysql_real_escape_string($_POST['nbmatch_4vs5West']); addMatchupLines($luser, $round, '4vs5West', $choice_4vs5West, $number_matches, $lconn); }else { echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Les choix ont deja ete faits'; echo '</fieldset>'; } } function addPlayers($conn) { global $nombre_joueurs; $nbjoueurs = $nombre_joueurs; global $user; $luser = $user; $lconn = $conn; $luser = mysql_real_escape_string($user); //We retrieve the matchup list for the Western conference $sql_players =<<<SQL SELECT 'username' from players_choices where players_choices.username ='$luser'; SQL; $result = mysql_query($sql_players ,$lconn); $num_rows = mysql_num_rows($result); //The user of which we are trying to write the matchup does not exist so we can add it if($num_rows == 0){ //We add the 10 players for ($i=1; $i <= $nbjoueurs; $i++) { $player = mysql_real_escape_string($_POST['player_'.$i]); addPlayersLines($luser,$player, $lconn); } }else { echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Les choix de joueurs ont deja ete faits'; echo '</fieldset>'; } } function addfinalist($conn) { global $user; $luser = $user; $lconn = $conn; $luser = mysql_real_escape_string($user); //We retrieve the matchup list for the Western conference $sql_finalist =<<<SQL SELECT 'username' from finalists_choices where finalists_choices.username ='$luser'; SQL; $result = mysql_query($sql_finalist ,$lconn); $num_rows = mysql_num_rows($result); //The user of which we are trying to write the matchup does not exist so we can add it if($num_rows == 0){ //We add the matchups //On recupere les finalistes $finalistEast = mysql_real_escape_string($_POST['finalistEast']); $finalistWest = mysql_real_escape_string($_POST['finalistWest']); addfinalistLines($luser, "East", $finalistEast,$lconn); addfinalistLines($luser, "West", $finalistWest,$lconn); //Western conference }else { echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Les choix des finalistes ont deja ete faits'; echo '</fieldset>'; } } function addChampion($conn) { global $user; $luser = $user; $lconn = $conn; $luser = mysql_real_escape_string($user); //We retrieve the matchup list for the Western conference $sql_matchup =<<<SQL SELECT 'username' from champions_choices where champions_choices.username ='$luser'; SQL; $result = mysql_query($sql_matchup ,$lconn); $num_rows = mysql_num_rows($result); //we add the user's champion if($num_rows == 0){ $champion = mysql_real_escape_string($_POST['champion']); addChampionsLine($luser, $champion,$lconn); }else { echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Les choix du champion ont deja ete faits'; echo '</fieldset>'; } } function addgoalie($conn) { global $user; $luser = $user; $lconn = $conn; $luser = mysql_real_escape_string($user); //We retrieve the matchup list for the Western conference $sql_matchup =<<<SQL SELECT 'username' from goalies_choices where goalies_choices.username ='$luser'; SQL; $result = mysql_query($sql_matchup ,$lconn); $num_rows = mysql_num_rows($result); //we add the user's champion if($num_rows == 0){ $goalie = mysql_real_escape_string($_POST['goalie']); addGoaliesLine($luser, $goalie, $lconn); }else { echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Les choix du champion ont deja ete faits'; echo '</fieldset>'; } } function addfinalistLines($user,$conference, $finalist, $connection) { $sql_insert =<<<SQL insert into finalists_choices(username, conference, finalist) values ('$user' , '$conference', '$finalist'); SQL; $result = mysql_query($sql_insert ,$connection); if(!$result){ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Erreur a l\'insertion finalistes'; echo '</fieldset>'; } } function addChampionsLine($user, $champion, $connection) { $sql_insert =<<<SQL insert into champions_choices(username, champion) values ('$user' , '$champion'); SQL; $result = mysql_query($sql_insert ,$connection); if(!$result){ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Erreur a l\'insertion champion'; echo '</fieldset>'; } } function addGoaliesLine($user, $goalie, $connection) { $sql_insert =<<<SQL insert into goalies_choices(username, goalie) values ('$user' , '$goalie'); SQL; $result = mysql_query($sql_insert ,$connection); if(!$result){ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Erreur a l\'insertion du gardien'; echo '</fieldset>'; } } function addMatchupLines($user, $round, $matchup, $choice, $games, $connection) { $sql_insert =<<<SQL insert into matchup_choices(username, round, matchup, choice, number_matches) values ('$user' , $round, '$matchup', '$choice', $games); SQL; $result = mysql_query($sql_insert ,$connection); if(!$result){ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Erreur a l\'insertion matchup'; echo '</fieldset>'; } } function addPlayersLines($user, $player, $connection) { $sql_insert =<<<SQL insert into players_choices(username, player) values ('$user' , '$player'); SQL; $result = mysql_query($sql_insert ,$connection); if(!$result){ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo 'Erreur a l\'insertion joueurs'; echo '</fieldset>'; } } function choosePlayers($error) { //Choix des dix joueurs global $nombre_joueurs; $nbjoueurs = $nombre_joueurs; echo '</br>'; echo '<fieldset>' . "\n"; echo '<ol>' . "\n"; for ($i=1; $i <= $nbjoueurs; $i++) { echo '<li><input name="player_' . $i . '" id="player_' .$i . '"' . (isset($error["player_" . $i]) ? ' class="error"' :''); echo 'value="'; if(isset($_POST['player_' . $i])) echo $_POST['player_' . $i] ; echo '" type="text" size="30"></li></br>' . "\n"; } echo '</ol>'; echo '</fieldset>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153755-solved-header-error-im-desperate/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2009 Share Posted April 12, 2009 Output at line 1 errors that are not caused by characters in the file are caused by the BOM (Byte Order Mark) characters of a file that has been saved in UTF-8 format. Save your file in ANSI format. Quote Link to comment https://forums.phpfreaks.com/topic/153755-solved-header-error-im-desperate/#findComment-808073 Share on other sites More sharing options...
simpli Posted April 12, 2009 Author Share Posted April 12, 2009 What if I need the file to be in UTF format? (I need to be able to show accented characters). Quote Link to comment https://forums.phpfreaks.com/topic/153755-solved-header-error-im-desperate/#findComment-808087 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2009 Share Posted April 12, 2009 Save it without the BOM. If your editor does not offer that choice, find a different editor. Quote Link to comment https://forums.phpfreaks.com/topic/153755-solved-header-error-im-desperate/#findComment-808094 Share on other sites More sharing options...
simpli Posted April 14, 2009 Author Share Posted April 14, 2009 You're a geniusss it worked JR Quote Link to comment https://forums.phpfreaks.com/topic/153755-solved-header-error-im-desperate/#findComment-809532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.