Jump to content

Archived

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

Mutley

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

Recommended Posts

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:
[quote]Parse error: parse error, unexpected T_VARIABLE on line 21[/quote]

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

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

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


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

[code]<?
$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);
?>[/code]

Thanks.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

[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($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";

?>[/code]

Share this post


Link to post
Share on other sites
I switched it around to this:

[code]$team = "under_7s";
$menu = "$addprofile, $manageprofile, $newsform, $logout";
draw_admin_menu($menu, $team);
[/code]

No luck, still an empty white page.

Thanks for your time so far.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Try:

[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>";
$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);

?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Tried it all, still blank page. <br /> is there because it isn't in the function. Just as standalone html. ???

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
It is definatly the functions, having $ in a $=... like my topic title says. I did this code:

[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);

?>[/code]

...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:
[code]$menu = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
draw_admin_menu($menu, $team)
INCLUDES;[/code]

Still nothing worked.

Share this post


Link to post
Share on other sites
it may be that you're missing semicolons.  Try:

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

[/code]

Share this post


Link to post
Share on other sites
Nope.

Here is the code as it stands:
[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 = <<<INCLUDES
$addprofile, $manageprofile, $newsform, $logout;
draw_admin_menu($menu, $team)
INCLUDES;

?>[/code]


Someone must know why. :(

Share this post


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

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

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

Share this post


Link to post
Share on other sites
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 [code=php:0]global $logged;[/code] Also your parameters where in the wrong order too in your function, and you was calling your function in the wrong place. Try this:
[code]<?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[/code]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
What happens if you use this as the function:

[code=php:0]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;
}[/code]


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

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=103422.msg412637#msg412637 date=1155150632]
What happens if you use this as the function:

[code=php:0]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;
}[/code]


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

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!

Share this post


Link to post
Share on other sites

×

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.