2013-11-14 119 views
0

完整的錯誤:解析錯誤:語法錯誤,在/home/u572186424/public_html/safe.php意外T_VARIABLE上線56PHP語法錯誤...意外的T_VARIABLE?

我在第56行一直盯着,不能看着辦吧......

 exit(); 

整個文件如下:

<?php include_once("connect.php"); ?> 
<? 
$sql = "SELECT * FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; 
$query = mysql_query($sql) or die(mysql_error()); 
$row = mysql_fetch_object($query); 
$id = htmlspecialchars($row->id); 
$userip = htmlspecialchars($row->userip); 
$username = htmlspecialchars($row->username); 
$password = htmlspecialchars($row->password); 
$account_type = htmlspecialchars($row->account_type); 
$money = htmlspecialchars($row->money); 
$exp = htmlspecialchars($row->exp); 
$req_exp = htmlspecialchars($row->req_exp); 
$level = htmlspecialchars($row->level); 
$health = htmlspecialchars($row->health); 
$max_health = htmlspecialchars($row->max_health); 
$lastactive = htmlspecialchars($row->lastactive); 
$energy = htmlspecialchars($row->energy); 
$max_energy = htmlspecialchars($row->max_energy); 
$will = htmlspecialchars($row->will); 
$max_will = htmlspecialchars($row->max_will); 
$brave = htmlspecialchars($row->brave); 
$max_brave = htmlspecialchars($row->max_brave); 
$strength = htmlspecialchars($row->strength); 
$agility = htmlspecialchars($row->agility); 
$guard = htmlspecialchars($row->guard); 
$labor = htmlspecialchars($row->labor); 
$iq = htmlspecialchars($row->iq); 
$rank = htmlspecialchars($row->rank); 
?> 
<?php 
$sql = "SELECT * FROM sitestats WHERE id='1'"; 
$query = mysql_query($sql) or die(mysql_error()); 
$row = mysql_fetch_object($query); 
$admins = htmlspecialchars($row->admins); 
$mods = htmlspecialchars($row->mods); 
$hdo = htmlspecialchars($row->hdo); 
$admins_ip = htmlspecialchars($row->admins_ip); 
$mods_ip = htmlspecialchars($row->mods_ip); 
$admin_array = explode("-", $admins); 
$mod_array = explode("-", $mods); 
$hdo_array = explode("-", $hdo); 
$admin_ip_array = explode("-", $admins_ip); 
$mod_ip_array = explode("-", $mods_ip); 
?> 
<html> 
<body> 
<? 
if(isset($_SESSION['user_id'])) { 
$sql = "UPDATE users SET lastactive=NOW() WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; 
    mysql_query($sql); 
}else{ 
    header("Location: logout.php"); 
    exit(); //ERROR HERE 
} 
$query = "SELECT account_type,rank FROM users WHERE username= "$username"; 
$result = mysql_query($query) or die(mysql_error()); 
$row = mysql_fetch_array($result); 
if($row['account_type'] == 1){ 
$row['rank'] = "Player"; 
$rank = "Player"; 
}elseif($row['account_type'] == 2){ 
$row['rank'] = "VIP"; 
$rank = "VIP"; 
}elseif($row['account_type'] == 3){ 
$row['rank'] = "HDO"; 
$rank = "HDO"; 
}elseif($row['account_type'] == 4){ 
$row['rank'] = "Moderator"; 
$rank = "Moderator"; 
}elseif($row['account_type'] == 5){ 
$row['rank'] = "Admin"; 
$rank = "Admin"; 
}elseif($row['account_type'] == 6){ 
$row['rank'] = "Owner"; 
$rank = "Owner"; 
} 
?> 
</body> 
</html> 

順便說一句,這個代碼是在PHP中,如果你一直無法分辨。請幫幫忙!謝謝!

+0

錯誤是這裏**的用戶名=」 。$ username ** –

+0

喲,縮小一點讓我們可以真正閱讀它?此外,減少代碼,直到錯誤消失。當它發生時,你剛纔刪除的內容導致了錯誤。通常你首先這樣做,因爲你需要在發佈問題之前找到問題 –

回答

2

語法高亮顯示給你。問題是多餘的報價 「在這裏:

$query = "SELECT account_type,rank FROM users WHERE username= "$username"; 

嘗試:

$query = "SELECT account_type,rank FROM users WHERE username= '$username'"; 
+0

完美!謝謝! – Jacob

+0

如果你的字符串使用雙引號,你也可以編寫一個變量,而不必關閉引號,再次打開並打開,如下所示:$ query =「SELECT something FROM someTable WHERE condition = {$ condition}」; –

+0

並注意單引號的使用,因爲我假定用戶名是db中的text/varchar。 – AbraCadaver

0

當您連接查詢和$username有沒有點:

$query = "SELECT account_type,rank FROM users WHERE username= "$username"; 
+0

您不需要在PHP中將字符串與包含字符串的變量連接起來。你可以這樣做: $ query =「SELECT account_type,rank FROM users where username = $ username」; –

+0

沒錯,您必須將變量放在引號內,或者將其連接起來。不是中途。 – regulus

相關問題