I am trying to get the usernames of users to appear in the url so that I can use $_GET['username'] to grab the username to create a link to the user's profile which can be viewed by any logged in user. So far I can only the logged in user's username to display in url.
So I did a loop/queried the database and selected usernames of all users and created a link of the usernames to appear in the url. So any logged in user can go to the users.php and click on any username to see the detailed information of that user. Only logged in users will be able to access the profile.php and users.php.
So far this is what I have
session_start();
include 'includes/dbh.php';
$sql = "SELECT * FROM users";
$query = $conn->query($sql);
$num = $query->num_rows;
if($num > 0){
while($row = $query->fetch_assoc()){
$users[]= $row;
foreach($users as $user){
$usersUsername = $user['usersUsername'];
echo '<a href="profile.php?user="'.$usersUsername.'">'.$usersUsername.'</a><br>';
}
}
}
But the url appears in the browser like this: http://localhost/object/profile.php?user=
I need it be something like http://localhost/object/profile.php?user=nanakumi75
The username is missing. I need some help here