Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Display Admin Link


  • Please log in to reply
25 replies to this topic

#13 Bioshox

Bioshox

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 210 posts

Posted 17 February 2010 - 01:26 AM

This is still not working, even with the session and when there logged in!

The same error! ): D:
  • 0

#14 webcodez

webcodez

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 143 posts

Posted 17 February 2010 - 03:44 AM

Hmm that's weird...

I'll try it myself here and see if it works for me with an example post (should just work).

And try echoing $_SESSION['username'] to be sure that it's not empty and make sure the username echoed is a valid existing username in the database table.


echo $_SESSION['username'];


You could also try adding or die(mysql_error()) after the $get_role query to check what error it returns:


$get_role = mysql_query("SELECT role FROM users WHERE username = '".$_SESSION['username']."' ")or die(mysql_error());


I usually try doing such things to debug and see what;s wrong. And as you're writing such a big script you'll need to do this much more often probbably as there'll be a lot of things at first which won't instantly work, so debugging will be very important to retrieve errors quickly. I'll test it now on my pc and try debug it for you to see what's wrong if not database/session variable :)

EDIT: Did you actually connect to your database? ^^

>SOLUTION ( I think ;) )<


mysql_connect("localhost", "root", "password");
mysql_select_db("database");

  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#15 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 17 February 2010 - 03:48 AM

Hm.. mate, how did you set that session ?


$ses = $_SESSION['username'];

$sql = "SELECT permission FROM users WHERE username='".mysql_real_escape_string($ses)."'";
$query = mysql_query($sql);

$row = mysql_fetch_array($query);

$admin = $row['permission'];

// Admin permissions set as 'admin'
// User permissions set as 'user'

if($admin == "admin"){

echo "Display admin link!";

}else{

echo "No admin link!";

}


This should do the trick.. but if you don't have session correctly set then it wont work.
  • 0

#16 Bioshox

Bioshox

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 210 posts

Posted 17 February 2010 - 04:08 AM

Hm.. mate, how did you set that session ?


$ses = $_SESSION['username'];

$sql = "SELECT permission FROM users WHERE username='".mysql_real_escape_string($ses)."'";
$query = mysql_query($sql);

$row = mysql_fetch_array($query);

$admin = $row['permission'];

// Admin permissions set as 'admin'
// User permissions set as 'user'

if($admin == "admin"){

echo "Display admin link!";

}else{

echo "No admin link!";

}


This should do the trick.. but if you don't have session correctly set then it wont work.




I tried your code and modified it to my script

<?php
	$ses = $_SESSION['name'];

$sql = "SELECT role FROM users WHERE username='".mysql_real_escape_string($ses)."'";
$query = mysql_query($sql);

$row = mysql_fetch_array($query);

$admin = $row['role'];

// Admin permissions set as 'admin'
// User permissions set as 'user'

if($admin == "1"){

     echo "Display admin link!";

}else{

    echo "No admin link!";

}  
	?>

but now I get this error


PHP Error Message

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a2469246/public_html/live/demo/index.php on line 45

No admin link!


Thabk's for your help D:!!!
  • 0

#17 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 17 February 2010 - 04:16 AM

at times, if you use reserved words for table names or field names in MySQL, you will need to mark in the names with backticks (`) to make it work properly.

Your SQL would then be:
SELECT `permission` FROM `users` WHERE `username`='".mysql_real_escape_string($ses)."'"

  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#18 Bioshox

Bioshox

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 210 posts

Posted 17 February 2010 - 04:32 AM

I still got the same error I'm afraid!
  • 0

#19 webcodez

webcodez

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 143 posts

Posted 17 February 2010 - 04:37 AM

Bioshock did you connect to database & host?
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#20 Bioshox

Bioshox

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 210 posts

Posted 17 February 2010 - 04:40 AM

Yeah, I included the Config file at the top of the PHP page,

Here is all the code: (i know the part of the code is in comments, i did this so it didnt run while i debugged another feature)

<!-- Copyright Jacob Clark 2010 | Fusion Strike Studios and Network -->
<!-- Fusion Strike; Live! Was Developed In Loving Memory Of Frederick Clark -->
<!-- Please Do Not Remove These Comments -->

<?php 
//Get's Connection information
include "config.php";
?>

<html>
<head>
<title>Fusion Strike; Live!</title>
<link rel="stylesheet" href="style.css" type="text/css" >
</head>
<body>
<!-- Site Logo -->
<img src="images/logo.png">
<br>
<div id="page-wrap">

	<h4>
		<?php include "bloginfo.php"; ?>
	
	</h4>

<h6>
	
	<?php include "navigation.php"; ?>
	
</div>
</h6>

<div id="page-wrap">
	<?php
	//Get's The Display Posts File
	include "getposts.php";
	?>
	
	<?php
	//$ses = $_SESSION['name'];
	//$sql = "SELECT `role` FROM `users` WHERE `username`='".mysql_real_escape_string($ses)."'";
	//$query = mysql_query($sql);

	//$row = mysql_fetch_array($query);

	//$admin = $row['role'];

	// Admin permissions set as 'admin'
	// User permissions set as 'user'

//if($admin == "1"){

     //echo "Display admin link!";

//}else{

    //echo "No admin link!";

//}  
	?>
	
	
</div>



<br>	

		<?php include "footer.php"; ?>

  • 0

#21 webcodez

webcodez

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 143 posts

Posted 17 February 2010 - 04:46 AM

You sure that:

- the connection to host & database was successfully
- $_SESSION['username'] contains a username of an existing user in table 'users' of database


And try to add or die(mysql_error()) to the query and connection and could you then post all errors it returns?

So:


$query = mysql_query($sql)or die(mysql_error());


Same for connection functions.

And did you echo the $_SESSION['name'] variable? (did it output an existing username?)
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#22 Bioshox

Bioshox

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 210 posts

Posted 17 February 2010 - 04:50 AM

Yeah, its all working, as teh navigation wouldent change when loged in.

So the sessions and config are correct as its displaying posts also.

):
  • 0

#23 webcodez

webcodez

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 143 posts

Posted 17 February 2010 - 04:59 AM

Lol this is very strange :o

Did you add 'or die(mysql_error())' without the quotes behind the query? What error did it return?
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#24 Bioshox

Bioshox

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 210 posts

Posted 17 February 2010 - 05:03 AM

Unknown column 'username' in 'where clause'

Thats the error
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download