I'm trying to make a PHP script that pulls records from a database and displays them on Bootstrap cards. However, when I try to run the page the script is on, I get a 500 error; removing the script from the page resolves the error. This is what I have (certain fields redacted for obvious reasons):
<?php
try {
$link = new \PDO("mysql:host=[REDACTED];dbname=[REDACTED];charset=utf8mb4", "[REDACTED]", "[REDACTED]", array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_PERSISTENT => false));
$handle = $link->prepare("SELECT expack, tier, raidName, picPath, bosses, downedBossesNormal, downedBossesSavage FROM raids WHERE expack = 4 ORDER BY tier DESC");
$handle->execute();
$result = $handle->fetchAll(\PDO::FETCH_OBJ);
print("<div class=\"card-columns\">")
foreach($result as $row) {
print("<div class=\"card\"><img class=\"card-img-top\" src=\"");
print($row->picPath);
print("\"><div class=\"card-header\"><h4 class=\"card-title\">");
print($row->raidName);
print("</h4>");
}
}
catch(\PDOException $ex) {
print($ex->getMessage());
}
?>
Out of the SQL fields mentioned, raidName
and picPath
are varchar
fields, and the others are all int
fields.
Since this is my first ever PHP project, I probably did something stupid to cause this 500 error; I just don't know what it was. Any help would be greatly appreciated. Thank you!