Jump to content

undefined variable


elite_prodigy

Recommended Posts

I have no idea what is going on here. I'm doing something very similar elsewhere in my site, and it works, but this

is not working....

 

This page is included in a file called main.php which sets up which files to include and includes every other file

for my Site Control Pannel, I include main.php in index.php. This file gets the permissions stored in the database

and builds a list of links based on those permissions.

 

This file gives no errors, but when I try to echo the variables to the page, I get a

 

Notice: Undefined variable: pages_Links in C:\wamp\www\team\index.php on line 55

 

and so on for each variable I attempt to echo.

 

I've tried including this file in index.php itself, but I get the same error.

 

Well, without further ado, here is the file:

<?php

include 'config.php';

mysql_select_db("exembar_site");

$id = $_SESSION['id'];


$sql		= "SELECT * FROM `permissions` WHERE `id`='{$id}'";
$result		= mysql_query($sql);
$info		= mysql_fetch_array($result);

$pages		= $info['pages'];
$staff		= $info['staff'];
$profile	= $info['profile'];
$security	= $info['security'];

//set permissions for page modification
if($pages == 1){
define				= $pages_links, '
					<a href="<?php echo $root; ?>index.php?action=0">Edit</a>
					<a href="<?php echo $root; ?>index.php?action=1">Create</a>
					<a href="<?php echo $root; ?>index.php?action=2">Delete</a>
					';
}
else{
$pages_links 		= "Access Denied";
}

//set permissions for staff modification
if($staff == 1){
$staff_links		= '
					<a href="<?php echo $root; ?>index.php?action=3">Hire</a>
					<a href="<?php echo $root; ?>index.php?action=4">Fire</a>
					';
}
else{
$staff_links 		= "Access Denied";
}

//set permissions for profile modification
if($profile == 1){
$profile_links		= '
					<a href="<?php echo $root; ?>index.php?action=5">Options</a>
					';
}
else{
$profile_links 		= "Access Denied";
}

//set permissions for site security modification
if($security == 1){
$security_links		= '
					Comming Soon
					';
}
else{
$security_links 		= "Access Denied";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/136721-undefined-variable/
Share on other sites

are u able in PHP to do this:

if($pages == 1){
   define            = $pages_links, 
                  <a href="<?php echo $root; ?>index.php?action=0">Edit</a>
                  <a href="<?php echo $root; ?>index.php?action=1">Create</a>
                  <a href="<?php echo $root; ?>index.php?action=2">Delete</a>
                  ';
}

I see a problem with line 3-5 of the above... but I'm relatively new to PHP.

Link to comment
https://forums.phpfreaks.com/topic/136721-undefined-variable/#findComment-713982
Share on other sites

umm, not exactly what I was talking about. I use white space all the time for readability...

what I mean is that this is all in <?php ?> tags but then on those lines he says

<a href="<?php echo $root; ?>index.php?action=0">Edit</a>

but like I said, I'm kinda a noob and I don't know all of the rules of PHP

Link to comment
https://forums.phpfreaks.com/topic/136721-undefined-variable/#findComment-713997
Share on other sites

<?php

include 'config.php';

mysql_select_db("exembar_site");

$id = $_SESSION['id'];


$sql		= "SELECT * FROM `permissions` WHERE `staffId`='{$id}'";
$result		= mysql_query($sql);
$info		= mysql_fetch_array($result);

$pages		= $info['pages'];
$staff		= $info['staff'];
$profile	= $info['profile'];
$security	= $info['security'];

//set permissions for page modification
if($pages == 1){
$pages_links		= '
					<a href="'.$root.'index.php?action=0">Edit</a>
					<a href="'.$root.'index.php?action=1">Create</a>
					<a href="'.$root.'index.php?action=2">Delete</a>
					';
}
else{
$pages_links 		= "Access Denied";
}

//set permissions for staff modification
if($staff == 1){
$staff_links		= '
					<a href="'.$root.'index.php?action=3">Hire</a>
					<a href="'.$root.'index.php?action=4">Fire</a>
					';
}
else{
$staff_links 		= "Access Denied";
}

//set permissions for profile modification
if($profile == 1){
$profile_links		= '
					<a href="'.$root.'index.php?action=5">Options</a>
					';
}
else{
$profile_links 		= "Access Denied";
}

//set permissions for site security modification
if($security == 1){
$security_links		= '
					Comming Soon
					';
}
else{
$security_links 		= "Access Denied";
}

?>

This is my current updated code, I fixed a lot of errors :/.

Link to comment
https://forums.phpfreaks.com/topic/136721-undefined-variable/#findComment-714103
Share on other sites

You're not supposed to use PHP tags the way I did. That happened because I was orriginally just placing the links there, and when I created the security settings, I just copy/pasted the links. And since the links were originally in an HTML page they had the Tags so that I could use the root address.

 

I'm getting an undefined variable as described in my first post.

Link to comment
https://forums.phpfreaks.com/topic/136721-undefined-variable/#findComment-714177
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.