title: img src showing wrong user from database
body: <p><strong>UPDATE</strong> I added this to my while loop during the array fetch. Does this work, or is there a better way? It is showing the correct pic now: </p>
  
  <pre><code>$query = "SELECT * FROM `users`";
  $result = mysqli_query($connection, $query);
  if ($result) {
       while ($row = mysqli_fetch_assoc($result)) {
           if($username == $row['username']) { //&lt;--- NEW CODE
                $profile_pic = '&lt;img src="' . $row['avatar'] . '" style = "width:70%" alt="Profile Photo"/&gt;';
           }
  
       }
  }
  </code></pre>
  
  <p>I tried to search for this, but couldn't find anything similar. I've edited nothing on my profile.php page. I created several test users to test the functionality of a live user search. Everything was working fine until I logged in as another user. The profile pic that is displayed in the browser is pointing to a different user, yet the real image path is correctly stored in the database. I deleted all users except for the original two, and nothing has changed. I haven't changed any code, but I will show the relevant code that displays the profile pic and the live search. 
  (<strong>Note</strong>: I will work on more secure queries later. Learning to translate into prepared statements as I go.)</p>
  
  <p>The pic container from profile.php. I'm even echoing the current username temporarily at the top left just to show that it's getting the correct name.</p>
  
  <pre><code>&lt;div id="avatar-container" class="dsh-display-container"&gt;
     &lt;button type="button" id="upload-toggle"&gt;&lt;i class="fa fa-camera"&gt;&lt;/i&gt;&lt;span&gt;  Update Avatar  &lt;/span&gt;&lt;/button&gt;
     &lt;?php
     $query = "SELECT * FROM `users`";
     $result = mysqli_query($connection, $query);
     if ($result) {
          while ($row = mysqli_fetch_assoc($result)) {
             $profile_pic = '&lt;img src="' . $row['avatar'] . '" style = "width:70%" alt="Profile Photo"/&gt;';
           }
     }
     ?&gt;
     &lt;?php echo $avatar_form; ?&gt;
     &lt;?php echo $profile_pic; ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is what is displaying on my profile:
  <a href="https://i.stack.imgur.com/ksnfa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ksnfa.png" alt="img src"></a></p>
  
  <p>On my search.php page, it displays correctly. </p>
  
  <p><a href="https://i.stack.imgur.com/5LP48.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5LP48.png" alt="correct img"></a></p>
  
  <p>This is what shows the info: </p>
  
  <pre><code>try {
  $db = new PDO("mysql:host=localhost;dbname=devSocial", "xxxxxxxxx", "xxxxxxxxxxxxx");
  } catch(Exception $e) {
      die("ERROR: ".$e-&gt;getMessage());
  }
  
  if (isset($_POST['username']) &amp;&amp; $_POST['username'] != "") {
  
  $req = $db-&gt;prepare("SELECT * FROM `users` WHERE username LIKE :username");
  $req-&gt;execute(array(
      'username' =&gt; '%' . $_POST['username'] . '%'
  ));
  if ($req-&gt;rowCount() == 0) {
      echo "Sorry. No one by that name found.";
  } else {
  
  while ($data = $req-&gt;fetch()) {
      $data['gender'] = ($data['gender'] == 'm') ? 'male' : 'female';
  
  ?&gt;
  &lt;div class="user"&gt;
      &lt;div class="img-container"&gt;
      &lt;img src="&lt;?php echo $data['avatar']; ?&gt;" class="userImage"&gt;
      &lt;/div&gt;
      &lt;span class="username"&gt;&lt;?php echo $data['username']; ?&gt;&lt;/span&gt;&lt;br/&gt;
      &lt;span class="gender"&gt;&lt;?php echo $data['gender'];?&gt;&lt;/span&gt;&lt;br/&gt;
      &lt;span class="profession"&gt;&lt;?php echo $data['profession']; ?&gt;&lt;/span&gt;&lt;br/&gt;
      &lt;span class="uni"&gt;&lt;?php echo $data['uni']; ?&gt;&lt;/span&gt;&lt;br/&gt;
      &lt;span class="degree"&gt;&lt;?php echo $data['degree']; ?&gt;&lt;/span&gt;&lt;br/&gt;
      &lt;span class="major"&gt;&lt;?php echo $data['major']; ?&gt;&lt;/span&gt;&lt;br/&gt;
      &lt;hr/&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I completely removed testUser from the database, and the profile displays correctly. </p>
  
  <p><a href="https://i.stack.imgur.com/8QT1J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8QT1J.png" alt="correct img"></a></p>
  
  <p>My main concern is that I changed nothing in those two segments of code and I was able to alternate between users. What is this voodoo? I've logged in as the two different users off and on for weeks and it showed correctly. I even went over my local history with a fine toothed comb and nothing has been changed. If someone could help that would be great because I've spent far too long. If I delete all but my "csheridan" user, it works. If I delete then recreate the testUser, my "csheridan" user now shows the default avatar. This is a major bug and I'm lost.</p>