title: Background from database with PHP / Undefined index
body: <p>I am making a website that is linked to a database. But I came across a problem that i cant seem to solve. I want to assign a background to a page when the ID in the URL is a certain number. So I made a Query:</p>
  
  <pre><code>&lt;?php
  
  require 'app/start.php';
  
  $pages = $db-&gt;query("
      SELECT id, name
      FROM sprints
  ")-&gt;fetchAll(PDO::FETCH_ASSOC);
  
  $vakid = $_GET["vak"];
  
  $bg = $db-&gt;query("
      SELECT background
      FROM categories
      WHERE id = $vakid
  ")-&gt;fetchAll(PDO::FETCH_ASSOC);
  
  require VIEW_ROOT . '/sprint.php';
  </code></pre>
  
  <p>The last query is the one that should take the background path! I included the other query for the page too, maybe it can help! I get the ID from the URL with $_GET.</p>
  
  <p>I tested this query and it works in my database.. but when i include it in my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
  
  
          &lt;link rel="stylesheet" href="&lt;?php echo BASE_URL?&gt;/CSS/CMSTutorial.css"&gt;
      &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="sprintwrap" style="background-image: url('&lt;?php echo e($bg['background']);?&gt;')"&gt;&lt;/div&gt;
      &lt;div id="sprintbg"&gt;
  
          &lt;?php if (empty($pages)): ?&gt;
              &lt;p&gt;Sorry, no pages at the moment.&lt;/p&gt;
          &lt;?php else: ?&gt;
              &lt;ul&gt;
                  &lt;?php foreach ($pages as $page): ?&gt;
                      &lt;li&gt;&lt;a href="&lt;?php echo BASE_URL; ?&gt;/vak.php?vak=&lt;?php echo $vakid ?&gt;&amp;sprint=&lt;?php echo $page['id']; ?&gt;"&gt;&lt;?php echo $page['name']; ?&gt;&lt;/a&gt;&lt;/li&gt;
                  &lt;?php endforeach; ?&gt;
              &lt;/ul&gt;
          &lt;?php endif; ?&gt;
  
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p> </p>
  
  <p>It doesn't work. I don't know what to do :( I hope you guys can help me! Thanks in advance!</p>
  
  <p>This is the error: Undefined index: background in /// on line 10 (the html file I included, sprintwrap div)</p>