Jump to content


Photo

function help "$this = $this2, $this3;" etc


  • Please log in to reply
18 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 08 August 2006 - 02:22 PM

I'm trying to make it simple to make several admin menus but can't seem to get this part right, I just get this error:

Parse error: parse error, unexpected T_VARIABLE on line 21


Here is the part I get confused with in bold, is this ok to do?

<?
$team
[b]$menu = $addprofile, $manageprofile, $newsform, $logout;	[/b]

	draw__admin_menu($menu, $team);
?>[/


Here is the full code, I hope you understand what I'm trying to do:

<?
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = "	- <a href=\"logout.php\">Logout</a>";

function draw_admin_menu($menu, $team) {

if($logged[username] && $logged[level] ==$team)
{
?>
<center>Welcome <b><?=$logged[username]?></b><br /></center><br /><br />
<?=$menu?><br /><br />
<?
}
}
?>
<br /><br /><br />
<?
$team
$menu = $addprofile, $manageprofile, $newsform, $logout;	

	draw__admin_menu($menu, $team);
?>

Thanks.
~ Mutley.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 August 2006 - 02:25 PM

You are misisng a semi-colon after $team

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 08 August 2006 - 02:32 PM

And after that you get error "Parse error: parse error, unexpected ',' in file_name on line x" because your assignment $menu=$addprofile must end with a semi-colon.

RTFM is an almost extinct art form, it should be subsidized.

#4 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 08 August 2006 - 02:36 PM

I've changed the common errors and commented it up but it still doesn't work, it won't display the content, I just get a blank white page:

<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = "	- <a href=\"logout.php\">Logout</a>";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($menu, $team) {

if($logged[username] && $logged[level] ==$team)
{
?>
<center>Welcome <b><?=$logged[username]?></b></center><br /><br />
<?=$menu?><br /><br />
<?
}
}
?>
<br /><br /><br />
<?

// Here is my admin menu calling the functions above

draw_admin_menu($menu, $team);
$team = "under_7s";
$menu = "$addprofile, $manageprofile, $newsform, $logout";

?>

~ Mutley.

#5 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 03:17 PM

you need to define $menu and $team before calling the function

#6 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 08 August 2006 - 03:28 PM

I switched it around to this:

$team = "under_7s";
$menu = "$addprofile, $manageprofile, $newsform, $logout";
draw_admin_menu($menu, $team);

No luck, still an empty white page.

Thanks for your time so far.
~ Mutley.

#7 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 03:44 PM

when you view the page source, do you see the '<br /><br /><br />', which would indicate that the function is being executed properly and the conditions set in your if statement are not bieng satisfied?

#8 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 08 August 2006 - 03:48 PM

Try:

<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = "	- <a href=\"logout.php\">Logout</a>";
$teamname = "under_7s";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($menu, $team) {
global $addprofile, $manageprofile, $newsform, $logout, $teamname;
$menu = "$addprofile, $manageprofile, $newsform, $logout";
$team = "$teamname";
return $menu, $team;

if($logged[username] && $logged[level] ==$team)
{
?>
<center>Welcome <b><?=$logged[username]?></b></center><br /><br />
<?=$menu?><br /><br />
<?
}
}
?>
<br /><br /><br />
<?

// Here is my admin menu calling the functions above
echo draw_admin_menu($menu, $team);

?>


#9 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 03:53 PM

the br's in my previous message about viewing the source code of your page were interpreted as line breaks.

your function prints out some line breaks, br's, at the end.  Check the source code of your blank page to see if those are there, which woul dindicate that the function is executing properly and the problem is probably that the conditions set in your if statement are not being satisfied.


#10 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 08 August 2006 - 06:18 PM

Tried it all, still blank page. <br /> is there because it isn't in the function. Just as standalone html. ???
~ Mutley.

#11 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 06:20 PM

replace the br's at the end of the function code with 'end of page', load the page and see if this text is displayed.  If so, the problem lies in the parameters sent to the function.

#12 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 08 August 2006 - 07:18 PM

It is definatly the functions, having $ in a $=... like my topic title says. I did this code:

<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = "	- <a href=\"logout.php\">Logout</a>";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($team, $menu) {

//if($logged[username] && $logged[level] ==$team)
//{
?>
<center>Welcome <b><?=$logged[username]?></b></center><br /><br />
<?=$menu?><br /><br />
<?
}
//}
?>
End of page
<?

// Here is my admin menu calling the functions above

$team = "under_7s";
$menu = "$addprofile, $manageprofile, $newsform, $logout";
draw_admin_menu($menu, $team);

?>

...commenting out the "$" parts and it loaded "under_7s" and the word "Welcome" but didn't load any of the $menu or name attributes?

I thought it might be a PHP problem, so did this in the $menu part:
$menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
draw_admin_menu($menu, $team)
INCLUDES;

Still nothing worked.
~ Mutley.

#13 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 07:52 PM

it may be that you're missing semicolons.  Try:

<center>Welcome <b><?=$logged[username];?></b></center><br /><br />
<?=$menu;?><br /><br />



#14 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 09 August 2006 - 11:57 AM

Nope.

Here is the code as it stands:
<?
// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = "	- <a href=\"logout.php\">Logout</a>";

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($team, $menu) {

//if($logged[username] && $logged[level] ==$team)
//{
?>
<center>Welcome <b><?=$logged[username];?></b></center><br /><br />
<?=$menu;?><br /><br />
<?
}
//}
?>
End of page
<?

// Here is my admin menu calling the functions above

$team = "under_7s";
$menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
draw_admin_menu($menu, $team)
INCLUDES;

?>


Someone must know why. :(
~ Mutley.

#15 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 01:48 PM

perhaps your server is not set up to use ASP style tags.  Try
//if($logged[username] && $logged[level] ==$team)
//{
?>
<center>Welcome <b><?PHP echo $logged[username];?></b></center><br /><br />
<?PHP echo $menu;?><br /><br />

Also, I don't understand the following lines of your code:
menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;

Perhaps <<<INCLUDES is something with which I am not familiar, or it's just your notation.

#16 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 August 2006 - 02:36 PM

Okay. looking at your code you are using an $logged variable in side the draw_admin_menu function. Now the function wont be able to access the $logged function as it is out side of the variable scope of the function. WHat you'll want to do is define as global inside the function like so
global $logged;
Also your parameters where in the wrong order too in your function, and you was calling your function in the wrong place. Try this:
<?php

// Here are the list of menu options I want to call
$addprofile = "- <a href=\"admin_profileform.php\">Add a new Profile</a>";
$manageprofile = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$newsform = "- <a href=\"admin_profilemanage.php\">Manage Profiles</a>";
$logout = "	- <a href=\"logout.php\">Logout</a>";

// Here is my admin menu calling the functions above
$team = "under_7s";
$menu = $addprofile . $manageprofile . $newsform . $logout;

// The draw function, so I can create a list of links and user levels instead of doing the same code repeatadly
function draw_admin_menu($menu, $team)
{
    global $logged; // define the $logged variable as global so we can access them from within the function.

    if($logged['username'] && $logged['level'] == $team)
    {
        $html = '<center>Welcome <b>' . $logged['username'] . '</b></center><br /><br />' . $menu . '<br /><br />';
    }

    echo $html;
}

draw_admin_menu($menu, $team);

?>
End of page


#17 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 09 August 2006 - 07:01 PM

Using that, all I see is "End of page". :(

Thanks for your effort so far. I'm really intrested to know what the problem is!
~ Mutley.

#18 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 August 2006 - 07:10 PM

What happens if you use this as the function:

function draw_admin_menu($menu, $team)
{
    global $logged; // define the $logged variable as global so we can access them from within the function.

    //if($logged['username'] && $logged['level'] == $team)
    //{
        $html = '<center>Welcome <b>' . $logged['username'] . '</b></center><br /><br />' . $menu . '<br /><br />';
    //}

    echo $html;
}


Do you get any output. Also where is the $logged variable being created to?

#19 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 09 August 2006 - 08:09 PM

What happens if you use this as the function:

function draw_admin_menu($menu, $team)
{
    global $logged; // define the $logged variable as global so we can access them from within the function.

    //if($logged['username'] && $logged['level'] == $team)
    //{
        $html = '<center>Welcome <b>' . $logged['username'] . '</b></center><br /><br />' . $menu . '<br /><br />';
    //}

    echo $html;
}


Do you get any output. Also where is the $logged variable being created to?


YES! Of course! I forgot to do include('config.php') at the top for my logged variable.

Ah thanks, it all works now. Jeez, thanks so much wildteen!
~ Mutley.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users