2016-05-15 91 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']; 

与其他词,你两次打电话给你行。如果你明白我的意思...