title: Trying to access array offset on value of type null (PHP)
body: <p>problem resolved (in comments)
  i am making a project for school and i am getting this error Trying to access array offset on value of type null on this line of code</p>
  <pre><code>&lt;div class=&quot;user-name&quot;&gt;&lt;?php echo $guests[&quot;firstName&quot;] ?&gt;&lt;/div&gt;
  </code></pre>
  <p>it is in this code and i retrieve the information out of a database</p>
  <pre><code>foreach((array)$result as $guests)
          {
      ?&gt;
      &lt;div class=&quot;posts-container&quot;&gt;
          &lt;div class=&quot;post-header&quot;&gt;
              &lt;div class=&quot;user-details&quot;&gt;
                  &lt;div class=&quot;user-name&quot;&gt;&lt;?php echo $guests[&quot;firstName&quot;] ?&gt;&lt;/div&gt;
                  &lt;div class=&quot;user-email&quot;&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;time&quot;&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;post-message&quot;&gt;
              &lt;h3&gt;&lt;/h3&gt;
              &lt;p&gt;&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php } ?&gt;
  </code></pre>
  <p>people asked for the sql code and the type/structure of $result
  type/structure:
  object(mysqli_result)#2 (5) { [&quot;current_field&quot;]=&gt; int(0) [&quot;field_count&quot;]=&gt; int(9) [&quot;lengths&quot;]=&gt; NULL [&quot;num_rows&quot;]=&gt; int(5) [&quot;type&quot;]=&gt; int(0)
  sql/database:</p>
  <pre><code>$servername = &quot;localhost&quot;;
  $username = &quot;root&quot;;
  $password = &quot;&quot;;
  $dbname = &quot;guestbook&quot;;
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);
  }
  
  $sql = &quot;SELECT id, firstName, lastName, email, title, message, URL, showEmail, Date FROM guestbook&quot;;
  $result = $conn-&gt;query($sql);
  
  $conn-&gt;close();
  </code></pre>