Profile Restrictions

When viewing different user profiles I do not want to enable the user that is logged in to have the opportunity to edit every users profile. That would be very problematic! I only want them to be able to edit their OWN profile.

Therefore I will need to create an if statement to say that, IF a user is logged in and the $profileusername matches the $username logged in, SHOW the edit profile button, ELSE, hide it or don’t show it with the empty div.

Here is the if else statement:

<?php
if ($profileusername == $username) {
?>

<a href=”editprofile”>
<div id=”pencil”><a href=”editprofilepage.php?user=<?php echo $myprofile;?>”>Edit<img src=”pen.png”></a></div>
</a></br>

<?php
}
else {
?>
<div id=”nopen”></div>
<?php
}
?>

I have had to break up the php code here simply because there is HTML code in between.

The following screenshots demonstrate that when ‘yes’ (user 78) is Logged in, the edit button (the pencil) shows, but when I manually change the URL to a different user profile such as user 50, the edit button disappears.

screen-shot-2014-12-30-at-09-36-541screen-shot-2014-12-30-at-10-03-04

Advertisements
This entry was posted in Code. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s