header () call not going where defined
<p>I have an icon which is surrounded by anchor tags in an echo statement:</p>

<pre><code>&lt;a href='/inc/favourite_post.php?id=$thought_id'&gt;
    &lt;span class='glyphicon glyphicon-heart-empty' aria-hidden='true' style='padding-right: 5px;'&gt;&lt;/span&gt; 
&lt;/a&gt;
</code></pre>

<p>When this icon is clicked, I need it to perform a PHP query which is found in <code>favourite_post.php</code>.</p>

<p>Here is <code>favourite_post.php</code> :</p>

<pre><code>$getid = $_GET['id'];
$favourited_by = $username;
/***********************/
//query to get user id
$get_uid = mysqli_query ($connect, "SELECT * FROM users WHERE username='$username'");
while($query = mysqli_fetch_array($get_uid)){
    $uid = $query['id'];
}
/***********************/
// get details of the post id and username
$get_id = mysqli_query ($connect, "SELECT * FROM user_thoughts WHERE added_by ='$user'");
$row_query = mysqli_fetch_array($get_id);
$fav_by = $row_query['favourited_by'];
$fav_status = $row_query['fav_status'];

$fav_query = mysqli_query ($connect, "INSERT INTO post_favourites (user_id, thought_id) VALUES ('$uid', '$getid')");

header ("Location: ../profile_page/$added_by");
</code></pre>

<p><strong>Problem walk through:</strong></p>

<ol>
<li>Assume I am logged in as Alice and I am on andersons <code>profile_page</code>. The URL at this point will read <code>http://localhost/profile_page/anderson</code>.</li>
<li>I like a post from <code>Anderson</code> and click the icon, which performs this query to favourite their post.</li>
<li>When a user favourites someone's post, I need the page's location to be on the same address, i.e. stay on <code>http://localhost/profile_page/anderson</code>. So in the <code>header()</code> call, I have specified it's location to be <code>../profile_page/$added_by</code>. <code>$added_by</code> is the username of the user and should take the user back to <code>http://localhost/profile_page/anderson</code>, but it doesn't.</li>
<li>When the icon is clicked, the address bar reads <code>http://localhost/profile_page/</code> .. meaning the <code>$added_by</code> variable is not being passed through.</li>
</ol>

<p><strong>Edit</strong>:</p>

<p>Here is where I have defined <code>$added_by</code>:</p>

<pre><code>$get_id = mysqli_query ($connect, "SELECT * FROM user_thoughts WHERE added_by ='$user'");
    $row_query = mysqli_fetch_array($get_id);
        $added_by = $row_query['added_by'];
        $fav_by = $row_query['favourited_by'];
        $fav_status = $row_query['fav_status'];
</code></pre>

<p>I have previously used <code>header ("Location: profile_page/$user")</code> on other pages. <code>$user</code> is the var which holds the data after <code>?u=</code> in the URL. <code>$added_by</code> obtains the same data from the data. <code>$user</code> and <code>$added_by</code> are both usernames for users, which is why I am stumped.</p>