2016-01-30 72 views
0

當我試圖在我的頭文件中設置一個用戶名時遇到了語法錯誤,當沒有名字和姓氏坐下時,使用用戶名填充標籤時處理異常,肯定是一個愚蠢的錯誤。 我在我的項目中使用Quadodo登錄腳本,很容易實現。PHP:語法錯誤,意外的'else'

下面是代碼:

if(isset($qls->user_info['firstname'] { 
    $realname = "$qls->user_info['firstname'] . ' ' . $qls->user_info['lastname']" 
} else { 
    $realname = "$qls->user_info['username']" 
}; 
+4

您的發言都忘了行分號。 –

+0

錯過了分號.. – ameenulla0007

+0

你是對的@RaviHirani – ameenulla0007

回答

1

你必須忘記分號,以及在你的代碼結尾括號。

// add two ending brackets in below line. 
    if(isset($qls->user_info['firstname'])) { 
     // add semicolon in this line 
     $realname = "$qls->user_info['firstname'] . ' ' . $qls->user_info['lastname']"; 
    } else { 
     // add semicolon in this line 
     $realname = "$qls->user_info['username']"; 
    } //removed semicolon 
+1

@GaganUpadhyay:謝謝兄弟,您錯過了兩個右花括號 –

+0

。我用評論編輯了我的答案。 –

+0

謝謝,我感覺很蠢!也許我在編碼時必須暫停一下! – andreaem

0
if(isset($qls->user_info['firstname'])){ 
    $realname = "$qls->user_info['firstname'] . ' ' . $qls->user_info['lastname']"; 
} else { 
    $realname = "$qls->user_info['username']"; 
} 

試試這個

0

這是因爲你真的搞砸了這段代碼。這是很好的版本:

if(isset($qls->user_info['firstname'])) { 
$realname = $qls->user_info['firstname'] . ' ' . $qls->user_info['lastname']; 
} else { 
$realname = $qls->user_info['username']; 
}; 

我會建議使用一些IDE它會告訴你,當你有語法錯誤

+0

我正在使用C9IDE,但我編了5個小時白色暫停!謝謝 – andreaem