0

Attempting to create a template for the header element of my PHP site within a functions page. I can get the template to function correctly using heredoc but when I try and include a foreach within this and inster the pdo script within the function I get an error 500 message and cannot work out what is causing the issue.

I need to be able to use a foreach as the data called is part of a site management system which can be changed form the backend.

function template_header($title, $head = '') {

    $social_icons = $site->prepare('SELECT * FROM socials');
    $social_icons->execute();
    $socialicons = $social_icons->fetchAll();

    // DO NOT INDENT THE BELOW CODE
echo <<<HEADER
<!DOCTYPE html>
<html lang="en">
<head>
    <title>$title - $site_name</title>
    $head
</head>
<body>
    // HTML HERE
HEADER;
    
    foreach ($socialicons as $sicons) {
        echo '<li>
                <a href="'.$sicons['social_url'].'" title="'.$sicons['social_name'].'">
                    <i class="fab fa-'.$sicons['social_fa_icon'].'"></i>
                </a>
              </li>';
    }
echo <<<HEADER
    // HTML HERE
HEADER;
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
James
  • 1
  • 2
    "500" doesn't tell anyone anything; activate error reporting and/or check your server's error logs for the actual, detailed error message. Which will likely have something to do with `$site` not being defined though. See the duplicate above. – deceze May 23 '23 at 07:28

0 Answers0