我有一個小的問題,以下的PHP代碼。在輸入的名字,我想展示自己的當前用戶名,通過$user->username
,只有它給了我下面的錯誤:問題與加載用戶類
Notice: Undefined variable: user in /home//domains//public_html/dev/edit_account.php on line 36
Notice: Trying to get property of non-object in /home//domains//public_html/dev/edit_account.php on line 36
在game_header.php文件我有
$user = new User($_SESSION['id']);
並認爲它會起作用,但可悲的是它沒有。
我也曾嘗試
$user = new User($_SESSION['id']);
的edit_account.php頁面上
,但我得到了同樣的錯誤。
這是edit_account.php代碼。
有沒有人知道我可能會在這裏做錯嗎?
include "game_header.php";
$_GET['type'] = isset($_GET['type']) && ctype_alpha($_GET['type']) ? trim($_GET['type']) : '0';
switch($_GET['type']) {
case 'profileoptions' : profile_options(); break;
default : profile_options();
}
function profile_options() {
echo '
';
include 'game_footer.php';
}
'session_start();'我沒看到它在任何地方。它是在所有的頁面還是你離開它? –
@Fred the session_start();位於文件頂部的game_header.php中。 – Codemunkie
它必須在所有正在使用的文件中,一般的經驗法則。可能是問題的「一部分」。 –