Page 1 of 1

Hiding areas depending on session value

Posted: Fri Jun 26, 2009 10:08 am
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 } ?>
 

Re: Hiding areas depending on session value

Posted: Fri Jun 26, 2009 2:20 pm
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?

Re: Hiding areas depending on session value

Posted: Fri Jun 26, 2009 9:35 pm
by a94060
ohh mann,i want to ruin it. I actually know the answer. :lol:

Re: Hiding areas depending on session value

Posted: Fri Jun 26, 2009 9:42 pm
by McInfo
PHP Manual: Comparison Operators

Edit: This post was recovered from search engine cache.

Re: Hiding areas depending on session value

Posted: Fri Jun 26, 2009 10:59 pm
by a94060
McInfo wrote:PHP Manual: Comparison Operators
I thought the goal was for the OP to find the answer and post it? :lol:

Re: Hiding areas depending on session value

Posted: Sat Jun 27, 2009 1:35 am
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.

Re: Hiding areas depending on session value

Posted: Sat Jun 27, 2009 7:26 am
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