2011-07-21 116 views
1

每當我的用戶轉到會話用戶名更改下方的頁面時。有人能告訴我爲什麼嗎?我會很感激。我有一種感覺,它可能與我在開始會話後聲明的while循環有關。PHP用戶登錄更改!

這是用戶名更改的頁面! (leaderboard.php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<?php 
session_start(); 

if ($_SESSION['username']) 

    $user = "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>"; 
else 
    die("You must be logged in!"); 

$connect = //CONNECT TO DATABASE 


$query = "SELECT @rank:= @rank + 1 as rank, s.* FROM (SELECT username, score, wins, games FROM stats, (SELECT @rank:=0) r ORDER BY score DESC LIMIT 10) s"; 

if ($query_run = mysql_query($query)) 
{ 
//begin table 
echo "<div class='container'> 
     <table class='tableposition' border='1' width='600' cellpadding='3' cellspacing='0'> 
     <caption>OVERALL RANKINGS</caption> 
     <tr class='tablehead'> 
     <th>RANK</th> 
     <th> USERNAME</th> 
     <th>OVERALL SCORE</th> 
     <th>WIN%</th> 
     </tr>"; 
//begin loop 
    while ($query_row = mysql_fetch_assoc($query_run)) 
    { 
    $rank = $query_row['rank']; 
    $username = $query_row['username']; 
    $score = $query_row['score']; 
    $wins = $query_row['wins']; 
    $games = $query_row['games']; 
    $winpere = $wins/$games * 100; 
    $winper = number_format($winpere,1); 

    echo "<tr class='tablecontents'> 
      <td>$rank</td> 
      <td>$username</td> 
      <td>$score</td> 
      <td>$winper %</td> 
     </tr> 
     "; 
    } 
//end loop 
//close table 
echo "</table> 
     </div>"; 


}else{ 
echo mysql_error(); 
} 

//superbox file 
include('superbox.php'); 
?> 
+0

請將代碼降低到最低程度,我們幾乎不需要知道您的等級名稱等等。使查看槽更容易,更有吸引力回答。 – Wrikken

+0

不要將整數轉換爲字符串('1235') – Fredrik

回答

5

我已經立即注意到需要修復的一個問題。 session_start是必須在應該由瀏覽器呈現的任何內容之前調用的那些方法之一。這意味着你需要做的:

<?php 
session_start(); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<?php 

// everything else. 

雖然我不能保證是你的問題的原因,它是絕對必要的。

+0

好的,我會對這些代碼進行更改。 – user830593