Hiding areas depending on session value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DAVID87
Forum Commoner
Posts: 29
Joined: Fri Jun 26, 2009 9:56 am
Location: Nottingham, UK

Hiding areas depending on session value

Post by DAVID87 »

Hi all,

Hope that someone out there can help.

I have the code below that I want to get working but no matter what I try it ALWAYS shows the code.

Basically when a user logs into the administraton area on my site, a session is logged with their username. I want the code below to work so that when this session equals a specific value the html code is shown, however if the specific session value is something else then some other HTML code is shown.

i.e. if user A logs in then can see section A and B on a page. However, if user B logs in they can only see section B.

The code that I have seems to either always show the code or always hide it.

here is the code:

Code: Select all

<h1>Administrator Account</h1>
<?php
 
include 'dbc.php';
 
$result = mysql_query("SELECT id,user_name,user_email FROM admin WHERE user_name = '$_SESSION[user_name]'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);
if ($row[1]='Webmaster')
{ echo 'not webmaster'; }
else
{
?>
 
HTML CODE TO BE SHOWN
 
<?php } ?>
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Hiding areas depending on session value

Post by requinix »

The problem is, surprise surprise, in the code that determines whether the "code" shows up.

Code: Select all

if ($row[1]='Webmaster')
The question is: do you know what the problem is?
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: Hiding areas depending on session value

Post by a94060 »

ohh mann,i want to ruin it. I actually know the answer. :lol:
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Hiding areas depending on session value

Post by McInfo »

PHP Manual: Comparison Operators

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:28 pm, edited 1 time in total.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: Hiding areas depending on session value

Post by a94060 »

McInfo wrote:PHP Manual: Comparison Operators
I thought the goal was for the OP to find the answer and post it? :lol:
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Hiding areas depending on session value

Post by McInfo »

What is the point of asking a question if you have to find the answer yourself?

It is not particularly helpful to assume that someone has or should have a particular amount of knowledge about a subject and go about dangling carrots. Perhaps DAVID87 is just learning PHP but has a background in a language such as Visual Basic where a single equal sign is used as a comparison operator. Or maybe it is a typo. It is easier for a new reader to notice a typo than it is for the author.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 12:29 pm, edited 1 time in total.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: Hiding areas depending on session value

Post by a94060 »

McInfo wrote:What is the point of asking a question if you have to find the answer yourself?

It is not particularly helpful to assume that someone has or should have a particular amount of knowledge about a subject and go about dangling carrots. Perhaps DAVID87 is just learning PHP but has a background in a language such as Visual Basic where a single equal sign is used as a comparison operator. Or maybe it is a typo. It is easier for a new reader to notice a typo than it is for the author.

im sorry. That makes a lot of sense. To the original poster, you need ==,instead of =. = Just assigns the value, while == does a comparison
Post Reply