0

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!

Tyll'a
  • 446
  • 1
  • 5
  • 14
  • 1
    Did you check your logs? – John Conde Sep 27 '18 at 17:48
  • Beyond the linked duplicates about enabling error reporting, always look in web server logs for generic 500 errors, regardless of what the server is doing. – Devon Sep 27 '18 at 17:51
  • I looked in the error logs on CPanel; they're empty. If there's another place I can look, that would be greatly appreciated. – Tyll'a Sep 27 '18 at 17:52
  • Ask your server admin. Fatal PHP errors should show up in the error log unless they have configured it differently. Beyond that, you should always enable error reporting during development. – Devon Sep 27 '18 at 17:55
  • I will do that then. How do I enable error reporting in PHP, by the way? – Tyll'a Sep 27 '18 at 17:56
  • Read the linked duplicates. – Devon Sep 27 '18 at 17:56
  • Thank you. Now I have a plan on where to go next. – Tyll'a Sep 27 '18 at 17:57
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180897/discussion-between-psduckie-and-devon). – Tyll'a Sep 27 '18 at 17:58

0 Answers0