Sheriff Said Elahl Sheriff Said Elahl - 6 months ago 17
PHP Question

php mysqli statement error

while performing the below php code an error appreas with

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.


the php 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).',';
}
?>


the error appears when I add the while part:

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


I applied the same on a different select and it works:

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


what is wrong with the first one?

Answer

Could it be that the query SELECT date, Subject, Desc FROM sherif_DCOAn contains a mysql reserved keyword, Desc. Put backticks around it like: `desc`. date might also be reserved.