Displaying a user profile page PHP

让人想犯罪 __ 提交于 2019-12-04 21:16:30

It would depend on how your profile.php page is handling the GET variable that determines the profile of the person you are showing. Let's say that the variable is called id and that you have a row in your members table also called id (which acts as the unique key), then your anchor tag would look like:

echo '<a class="viewProfile" href="profile.php?id=' . $r['id']. '"><button>View Profile</button></a>';

First retrieve the user_id of the user from the database as you are doing with the query. Then give this id to the profile link as:

echo '<a href="profile.php?userid=' . $user_id . '>Linkname</a>';

Then in profile.php get this variable through:

$id = $_GET['userid'];

This way you can show the relevant user's profile in the profile.php.

Hope you might get the idea to work on.

If you are producing a list of links to user profiles then there are a couple of different options:

You can either append a $_GET variable to the end of your link as previously mentioned by Lloyd

echo '<a href="profile.php?if=' . $r['id'] . '">';

or you can send a $_POST variable; the easiest way to do this would be to create a list of forms:

<?php 
$query = $db->query("SELECT * from members");
while($r = $query->fetch()) {
    echo '<div class="col-sm-6 col-md-6 col-lg-3 membersGrid">';
    echo '<div class="profileThumb">';
    echo '<img width="130" height="130" src="'.$r['profile_pic'].'"/><br>';
    echo $r['username'], '<br>';
    echo $r['country'], '<br>';
    echo '<form action="profile.php" method="post">';
    echo '<input type="hidden" value="' . $r['id'] . '" />';
    echo '<input type="submit" value="View Profile" />';
    echo '</form>';
    echo '</div>';
    echo '</div>';
}
?>

Sorry if I've misread your question, hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!