Current time: 05-24-2012, 04:07 PM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with PHP and a variable
11-09-2008, 01:38 AM
Post: #1
Issue with PHP and a variable
Alright, I made it so that I can use PHP in templates, but I am having this issue. I want to display a user's Group ID, but here's what happens:

If I put
PHP Code:
<?php
echo "{$mybb->user['usergroup']}";
?>
then it shows the Group ID, but get this error
PHP Code:
WarningUnexpected character in input'\' (ASCII=92) state=1 in directory/global.php(433) : eval()'d code(27) : eval()'d code on line 2

Warning: Unexpected character in input: '
\' (ASCII=92) state=1 in directory/global.php(433) : eval()'d code(27) : eval()'d code on line 2 

If I make it
PHP Code:
<?php
echo "\{$mybb->user['usergroup']\}";
?>
then the PHP errors disappear, but the variable shows
PHP Code:
\{Array[\usergroup\]\} 
instead of the Group ID.

What can I do? Or is there an alternate way? BTW, I am adding the PHP into the main header template.

Need web hosting? Try MyBBWebHost!
#1 for Running MyBB Communities

-------
Biodegradable Sunscreen - Unblock Facebook
Visit this user's website Find all posts by this user
Quote this message in a reply
11-09-2008, 03:23 PM (This post was last modified: 11-09-2008 03:24 PM by Tomm M.)
Post: #2
RE: Issue with PHP and a variable
How have you got to use PHP in templates - did you use a modification?

If so, you're probably best off looking into the author's support forums.

An alternative way would be do:

PHP Code:
<?php echo "{".$mybb->user['usergroup']."}"?>

... but I don't think it would make much difference (that's just the way I'd code it)...

Edit: Could it be to do with the { } tags?... try removing them or changing them to specialchars...
Find all posts by this user
Quote this message in a reply
11-09-2008, 04:55 PM (This post was last modified: 11-10-2008 01:55 AM by Zash.)
Post: #3
RE: Issue with PHP and a variable
(11-09-2008 03:23 PM)Tom.M Wrote:  How have you got to use PHP in templates - did you use a modification?

If so, you're probably best off looking into the author's support forums.

An alternative way would be do:

PHP Code:
<?php echo "{".$mybb->user['usergroup']."}"?>
I did that and it just deleted everything after it in the templates Sad
C'mon, nobody can help me?
Just bumping it so it goes back to the top.

Need web hosting? Try MyBBWebHost!
#1 for Running MyBB Communities

-------
Biodegradable Sunscreen - Unblock Facebook
Visit this user's website Find all posts by this user
Quote this message in a reply
11-10-2008, 07:57 PM
Post: #4
RE: Issue with PHP and a variable
Ok Bump? (Hoping this works)

Need web hosting? Try MyBBWebHost!
#1 for Running MyBB Communities

-------
Biodegradable Sunscreen - Unblock Facebook
Visit this user's website Find all posts by this user
Quote this message in a reply
11-10-2008, 07:59 PM
Post: #5
RE: Issue with PHP and a variable
Well this is obviously a problem with your modification. Can you post it here? I suspect you are having problems because $templates->get() automatically backslashes double quotation marks (") so I think you should stripslashes before you eval the PHP.

Dennis Tsang :: MyBB Developer
Follow me on Twitter: @dennistt
Visit this user's website Find all posts by this user
Quote this message in a reply
11-10-2008, 09:37 PM
Post: #6
RE: Issue with PHP and a variable
You can already just use a variable in the code though, if you're not meaning to extend it futher to functions and stuff.
Find all posts by this user
Quote this message in a reply
11-11-2008, 09:28 PM
Post: #7
RE: Issue with PHP and a variable
(11-10-2008 07:59 PM)DennisTT Wrote:  Well this is obviously a problem with your modification. Can you post it here? I suspect you are having problems because $templates->get() automatically backslashes double quotation marks (") so I think you should stripslashes before you eval the PHP.
This is the modification: http://community.mybboard.net/thread-318...+templates

(11-10-2008 09:37 PM)CraKteR Wrote:  You can already just use a variable in the code though, if you're not meaning to extend it futher to functions and stuff.

I am trying to make a PHP if else statement so that text would show if a member is in a certain group, but not in another.

Need web hosting? Try MyBBWebHost!
#1 for Running MyBB Communities

-------
Biodegradable Sunscreen - Unblock Facebook
Visit this user's website Find all posts by this user
Quote this message in a reply
11-12-2008, 10:00 PM
Post: #8
RE: Issue with PHP and a variable
Bump Sad

Need web hosting? Try MyBBWebHost!
#1 for Running MyBB Communities

-------
Biodegradable Sunscreen - Unblock Facebook
Visit this user's website Find all posts by this user
Quote this message in a reply
11-14-2008, 01:17 AM
Post: #9
RE: Issue with PHP and a variable
No Help?

Need web hosting? Try MyBBWebHost!
#1 for Running MyBB Communities

-------
Biodegradable Sunscreen - Unblock Facebook
Visit this user's website Find all posts by this user
Quote this message in a reply
11-14-2008, 02:49 AM
Post: #10
RE: Issue with PHP and a variable
This user has been denied support. This user has been denied support.
$mybb->user['usergroup']

Try it without the single quotes

$mybb->user[usergroup]

Also look into the displaygroup for the user...should be

$mybb->user['displayusergroup'] or something like that. Do a print_r($mybb->user) to get all the variables available.

New MyBB plugin is "My Awards 2.0".
[Image: 468x60_SF.gif]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication