2016-05-15 142 views
0

而與PHP mysqli的語句錯誤

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request. 
Please contact the server administrator to inform of the time the erro occurred and of anything you might have done that may have caused the error. 
More information about this error may be available in the server error log. 

執行下面的PHP代碼中的錯誤appreas PHP代碼:

while($row = mysqli_fetch_assoc($query)){Whatever code} 

<?php 
require "init.php"; 
$Date = []; 
$Subject = []; 
$Desc= []; 
$query = mysqli_query($con,"SELECT date, Subject, Desc FROM sherif_DCOAn"); 
while($row = mysqli_fetch_assoc($query)){ 
$Date[] = $row['date']; 
$Subject[] = $row['Subject']; 
$Desc[] = $row['Desc']; 
echo json_encode($Date).','.json_encode($Subject).','.json_encode($Desc).','; 
} 
?> 

當我添加的,而部分出現錯誤

我在一個不同的選擇上應用了它,它的工作原理如下:

$query = mysqli_query($con,"SELECT DISTINCT SiteName FROM CAB"); 

第一個錯在哪?

回答

2

您的查詢,SELECT date, Subject, Desc FROM sherif_DCOAn包含MySQL reserved keywords。列名爲date,SubjectDesc

你可以BACKTICK那些列名逃脫他們喜歡:

SELECT `date`, `Subject`, `Desc` FROM sherif_DCOAn 

,你應該是不錯的。僅供將來參考,我相當確定,建議不要在名稱中使用這些關鍵字。

+0

你救了我:) ..這是答案 –

+0

@SheriffSaidElahl我去過那裏的次數超過了我的數量!稍微闡述了答案,謝謝你的最佳答案。 –

+0

這些是列名,而不是表。 – jkavalik

-1

改變這一點:

$query = mysqli_query($con,"SELECT date, Subject, Desc FROM sherif_DCOAn"); 

到:

$query = mysqli_query($con,"SELECT * FROM sherif_DCOAn"); 
你在這裏呼喚你的結果

while($row = mysqli_fetch_assoc($query)){ 
$Date[] = $row['date']; 
$Subject[] = $row['Subject']; 
$Desc[] = $row['Desc']; 

與其他詞,你兩次打電話給你行。如果你明白我的意思...