I have an icon which is surrounded by anchor tags in an echo statement:
<a href='/inc/favourite_post.php?id=$thought_id'>
    <span class='glyphicon glyphicon-heart-empty' aria-hidden='true' style='padding-right: 5px;'></span> 
</a>
When this icon is clicked, I need it to perform a PHP query which is found in favourite_post.php.
Here is favourite_post.php :
$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");
Problem walk through:
- Assume I am logged in as Alice and I am on andersons profile_page. The URL at this point will readhttp://localhost/profile_page/anderson.
- I like a post from Andersonand click the icon, which performs this query to favourite their post.
- When a user favourites someone's post, I need the page's location to be on the same address, i.e. stay on http://localhost/profile_page/anderson. So in theheader()call, I have specified it's location to be../profile_page/$added_by.$added_byis the username of the user and should take the user back tohttp://localhost/profile_page/anderson, but it doesn't.
- When the icon is clicked, the address bar reads http://localhost/profile_page/.. meaning the$added_byvariable is not being passed through.
Edit:
Here is where I have defined $added_by:
$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'];
I have previously used header ("Location: profile_page/$user") on other pages. $user is the var which holds the data after ?u= in the URL. $added_by obtains the same data from the data. $user and $added_by are both usernames for users, which is why I am stumped.
 
     
     
    