0

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?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

2 Answers2

2

Your query, SELECT date, Subject, Desc FROM sherif_DCOAn contains MySQL reserved keywords. Your column names date, Subject and Desc are all listed.

You could backtick those column names to escape them like:

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

and you should be good. Just for future reference, I'm fairly sure it's recommended to simply not use those keywords in names for tables.

Algernop K.
  • 477
  • 2
  • 19
-1

change this:

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

to:

$query = mysqli_query($con,"SELECT * FROM sherif_DCOAn");

you're calling your results here:

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

With other words, you're calling your rows twice. If u kinda understand what i mean...