title: Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\twitter\core\classes\follow.php on line 25
body: <p>Everything seems to be working good but i am getting an error:</p>
  <p><a href="https://i.stack.imgur.com/NhTPV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NhTPV.png" alt="enter image description here" /></a></p>
  <p>I checked for typos in my follow.php and profile.php and even retyped the major part of the code but was not able to figure out the problem.
  This is my line 25 of follow.php</p>
  <pre><code>if($data['reciever'] == $profileID)
  </code></pre>
  <p><strong>Here is my follow.php</strong></p>
  <pre><code>    &lt;?php
  class Follow extends User
  {
      
      function __construct($pdo)
      {
          $this-&gt;pdo = $pdo;
      }
      public function checkFollow($followerID, $user_id)
      {
          $stmt = $this-&gt;pdo-&gt;prepare(&quot;SELECT * FROM `follow` WHERE `sender` = :user_id AND `reciever` = :followerID&quot;);
          $stmt-&gt;bindParam(&quot;:user_id&quot;, $user_id, PDO::PARAM_INT);
          $stmt-&gt;bindParam(&quot;:followerID&quot;, $followerID, PDO::PARAM_INT);
          $stmt-&gt;execute();
          return $stmt-&gt;fetch(PDO::FETCH_ASSOC);
      }
      
      public function followBtn($profileID, $user_id)
      {
          $data = $this-&gt;checkFollow($profileID, $user_id);
          if($this-&gt;loggedIn() === true)
          {
              if($profileID != $user_id)
              {
                  if($data['reciever'] == $profileID)
                  {
                      //Following Button
                      echo &quot;&lt;button class='f-btn following-btn follow-btn' data-follow='&quot;.$profileID.&quot;'&gt;Following&lt;/button&gt;&quot;;
                  }
                  else
                  {
                      //follow button
                      echo &quot;&lt;button class='f-btn following-btn follow-btn' data-follow='&quot;.$profileID.&quot;'&gt;&lt;i class='fa fa-user-plus'&gt;&lt;/i&gt;Follow&lt;/button&gt;&quot;;
                  }
              }
              else
              {
                  //edit button
                  echo &quot;&lt;button class='f-btn' onclick=location.href='profileEdit.php'&gt;Edit Profile&lt;/button&gt;&quot;;
  
              }
          }
          else
          {
              echo &quot;&lt;button class='f-btn' onclick=location.href='index.php'&gt;&lt;i class='fa fa-user-plus'&gt;&lt;/i&gt;Follow&lt;/button&gt;&quot;;
          }
      }
  }
  ?&gt;
  </code></pre>
  <p>The error states:</p>
  <blockquote>
  <p>Trying to access array offset on value of type bool</p>
  </blockquote>
  <p>and this is happening on line 25 of follow.php</p>
  <p>So, On looking at line 25 of follow.php</p>
  <pre><code>if($data['reciever'] == $profileID)
  </code></pre>
  <p>According to the error, we are trying to access an element in an array but the object is actually a boolean. So, $data must be a boolean. Looking a few lines up, on line 20 there is:</p>
  <pre><code>$data = $this-&gt;checkFollow($profileID, $user_id);
  </code></pre>
  <p>So $data is being set by the return value of checkFollow. checkFollow must be giving us a boolean. Looking at checkFollow we see it returns this:</p>
  <pre><code>return $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  </code></pre>
  <p>the boolean must be coming from $stmt-&gt;fetch. Let's look at the documentation for this method, which states:</p>
  <blockquote>
  <p>The return value of this function on success depends on the fetch
  type. In all cases, FALSE is returned on failure.</p>
  </blockquote>
  <p>My DB:</p>
  <p><a href="https://i.stack.imgur.com/1PMZR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1PMZR.png" alt="enter image description here" /></a></p>
  <p>So that's the source of the error. Why is fetch returning FALSE though?Maybe query is not returning any results. Perhaps there are no rows in the database that match the given parameters.But I don't know how to implement it as i am just beginning in PHP.If someone could show me the syntax for better clarification it would be highly appreciated.!
  Thank you!</p>