Please point me in the right direction

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

User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Please point me in the right direction

Post by diseman »

Well, that made perfect sense, but ADMIN is still not working; no data shown.

Logged in as USER with your updates and USER still works.

No ERRORS; just not showing any data from ADMIN side.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Please point me in the right direction

Post by shawngoldw »

What did you replace the following line with?

Code: Select all

if($_SESSION['isadmin'])
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Please point me in the right direction

Post by diseman »

Hi Shawn,

Your last question has confused me and now I feel like I've misunderstood something. So, here's what I have so far:

Code: Select all


<?php session_start();

// ----------------------------------------------------------------------------------------------------------
// Ensure the user has logged in and has proper access to this page
// ----------------------------------------------------------------------------------------------------------

$show = '';

if($_SESSION['isadmin'])
{
  $show = $_GET['email'];
}
elseif($_SESSION['myusername'])
{
  $show = $_SESSION['myusername'];
}

if($show){

include ("../modules/control_panel.php");
include ("../_includes/top.php");

?>
And then I have this...

Code: Select all


<?php

include ("../_includes/dbconnect.php");

// Query database for user's account for personalization ;

$query =  "SELECT * FROM users WHERE username = '".$show."' " ;

$result = mysql_query($query);

if (!$result) die(mysql_error());

else

{
	$row = mysql_fetch_object($result);

	$account	=	$row ->	account;
}

// Query database for user's first name and username for personalization ;

$query =  "SELECT * FROM users WHERE username = '".$show."' " ;

$result = mysql_query($query);

if (!$result) die(mysql_error());

else

{

	$row = mysql_fetch_object($result);

	$username 	= 	$row	->	username;
	$b_firstname 	= 	$row	->	b_firstname;
}

mysql_close($con);

?>
Did I miss something??
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Please point me in the right direction

Post by diseman »

Can't I just do something like:

Code: Select all


if($_SESSION['myusername'] or ($_SESSION['isadmin'])) 

..and have it work?
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Please point me in the right direction

Post by shawngoldw »

Use pipes (||) not or.

If you were to do that, what value would you use in the query?


Shawn
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Please point me in the right direction

Post by diseman »

Well, I tried it with the '".$show."' and if($_SESSION['isadmin']) just to be sure, but it didn't work.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Please point me in the right direction

Post by shawngoldw »

Sorry I missed the post a couple up, didn't realise you posted 2 in a row :oops:

This line:

Code: Select all

if($_SESSION['isadmin'])
was just an example I made up. Have you ever defined $_SESSION['isadmin']? Probably not, it was just a random variable I made up. I'm saying that you need to replace that with something which can identify that the user is an admin.
diseman wrote:Can't I just do something like:

Code: Select all


if($_SESSION['myusername'] or ($_SESSION['isadmin'])) 

..and have it work?
Yes you can do that, using || instead of or, but it is kind of redundant since you have already checked them in order to define $show with the proper value. You might as well just use $show so you don't have to check them in 2 places


Shawn
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Please point me in the right direction

Post by diseman »

Hi Shawn,

Thank you very much! Your last e-mail about 'defining the admin' tipped me off on what I was missing. I just defined a new user (admin) in the login script. Then, a few additional edits along with your IF/ELSEIF and all was working nicely.

That was a big hurdle for me. Thank you for sticking it out and coming back. Your help is greatly appreciated.

Have a good Labor Day weekend.

dM
Last edited by diseman on Sat Sep 04, 2010 9:07 am, edited 1 time in total.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Please point me in the right direction

Post by shawngoldw »

No problem, glad I could help! It was a good thing you bumped, your post kinda slipped by me a couple days a go, lol.

You have a good long weekend too, mines just going to be an opportunity to move back to school.

Shawn.
Post Reply