PHP用户登录了更改!

时间:2011-07-21 23:08:31

标签: php mysql

每当我的用户转到会话用户名更改下方的页面时。有人可以告诉我为什么吗?我会很感激。我觉得它可能与我在开始会话后声明的while循环有关。

这是用户名更改的页面! (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');
?>

1 个答案:

答案 0 :(得分: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.

虽然我不能保证这是你问题的原因,但绝对需要它。