Access Denied - why?

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
jjl
Forum Newbie
Posts: 13
Joined: Wed May 14, 2008 12:31 am

Access Denied - why?

Post by jjl »

When I use this function I get the "access denied" error but if I take the same code and insert in directly into the html page from where the function was called, it works fine. The function is stored separately in a file that is loaded with required.
Can anyone throw any light on the subject. Thanks

function CreateMenu ($menuname)
{
//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
echo "connected";
//build and issue the query and create the menu items
$sql = "SELECT * FROM $menu_table where `Menu` = '$menuname' ";

$result = @mysql_query($sql,$connection) or die(mysql_error());

while ($sql = mysql_fetch_object($result))
{
$filename = $sql -> Link;
$Text = $sql -> Title;
echo '<li>';
echo "<a href= $filename >$Text</a>";
echo '</li>';
}

}
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Access Denied - why?

Post by califdon »

Probably either the file or directory permissions for the include file are not the same as for your script, so it can't read the include file.
jjl
Forum Newbie
Posts: 13
Joined: Wed May 14, 2008 12:31 am

Re: Access Denied - why?

Post by jjl »

Thanks for the reply,
For some reason (I have yet to work out the intricacies of access for variables etc within php) the config file was not being read. It was required at the start of the html file under the php code. I included an include ( 'config.php') within the function and it all works fine now. Thanks again for your reply.
Jeremy
Post Reply