...

View Full Version : IPB not accepting custom codes



boeing747fp
10-16-2004, 03:19 PM
i cant get my code below to work in IPB... it just says UNEXPECTED T_ENCAPSED_WHITESPACE



$con = mysql_connect("localhost","user","pass");
$user = $_GET['showuser'];
$time = time()-900;
$sql = mysql_query("SELECT * FROM `ibf_sessions` WHERE `member_id` = '$user' AND `running_time` > '$time' LIMIT 1") or die(mysql_error());
if(mysql_num_rows($sql) >0){
$current_user_status = "Online";
}else{
$current_user_status = "Offline";
}


^ i put this in skin_profile.php and then in the Profile HTML modifier in IPB, i cant get the php code to work... it's supposed to show the user as being online or offline here http://condraft.com/boards/index.php?showuser=18

fci
10-16-2004, 04:40 PM
I see no syntax errors, maybe there is something above or below where you placed the code which you accidentially modified.. ?

and your link..

The following errors were found:
The board administrator does not allow Guests to post or reply. Please Login or Register to continue.

raf
10-16-2004, 06:11 PM
i cant get my code below to work in IPB... it just says UNEXPECTED T_ENCAPSED_WHITESPACE



$con = mysql_connect("localhost","user","pass");
$user = $_GET['showuser'];
$time = time()-900;
$sql = mysql_query("SELECT * FROM `ibf_sessions` WHERE `member_id` = '$user' AND `running_time` > '$time' LIMIT 1") or die(mysql_error());
if(mysql_num_rows($sql) >0){
$current_user_status = "Online";
}else{
$current_user_status = "Offline";
}


^ i put this in skin_profile.php and then in the Profile HTML modifier in IPB, i cant get the php code to work... it's supposed to show the user as being online or offline here http://condraft.com/boards/index.php?showuser=18

Do you have a linenumber with that error?
Also, i don't see you select a db anywhere ...

fci
10-16-2004, 07:41 PM
found this in the php extended manual chm when I was looking for something else ..

I got a "T_ENCAPSED_AND_WHITESPACE" parse error on one of my php files, and did not understand why.
When I read your post about this, I first of all tried the {} brackets idea, but found that it did not work. I then removed all instances of [' '] and replaced them with [ ]. Then it worked.
Satan


if you get a parse error saying that there was an unexpected T_ENCAPSED_AND_WHITESPACE, you've probably got an array within double quoted strings being parsed incorrectly.
For example:
$foo = $_GET['foo'];
echo "foo is $foo"; // works fine
However,
echo "foo is $_GET['foo']"; // parse error
Inside double-quoted strings, an identifier found within square brackets (after a variable, of course) is parsed as a string index. This identifier must be either a string, another variable, or a number. Since the single-quote around foo doens't fit (to the parser, anyway) any of these tokens, you get the parse error.
To remove the error, remove the single quotes, OR use the curly-brace syntax (recommended, as it's required for more complex substitution anyway).
echo "foo is {$_GET['foo']}"; // works
echo "foo is $_GET[foo]"; // also works

boeing747fp
10-17-2004, 12:36 AM
well, there's not an error when i just do that... but if i put that code above i mentioned into the IPB Profile skin, it just errors out... and i cant seem to get it to echo a session or regular variable either...
what i really need to know is this....

IPB has the template like this --> where they echo the user's name in the profile template, they only put {$info[member_name]}

i need to know how to make something like that so that in the html file, stuff inside the {} tags is parsed in PHP... i tried define() but that requires me to put <? and ?> around the echo {$}; tag... can anyone help me out figurin out how people do this {} in the html templates?

kliqster
10-17-2004, 01:07 AM
well, there's not an error when i just do that... but if i put that code above i mentioned into the IPB Profile skin, it just errors out... and i cant seem to get it to echo a session or regular variable either...
what i really need to know is this....

IPB has the template like this --> where they echo the user's name in the profile template, they only put {$info[member_name]}

i need to know how to make something like that so that in the html file, stuff inside the {} tags is parsed in PHP... i tried define() but that requires me to put <? and ?> around the echo {$}; tag... can anyone help me out figurin out how people do this {} in the html templates?

IPB doesn't parse PHP in it's templates - that includes the skin_*.php files.

What you need to do is this:

I assume you want to modify the profile view in some way, yeah? And that you're using v1.3(.1)?

Open up sources/Profile.php and find the following lines inside the view_profile function:


if ($info['posts_day'] > $member['posts'])
{
$info['posts_day'] = $member['posts'];
}

add the following code below:




$time = time() -900;
$sql = $DB->query( "SELECT * FROM `ibf_sessions` WHERE `member_id` = '{$ibforums->input['MID']}' AND `running_time` > '$time' LIMIT 1" );

if($DB->num_rows( $sql ) >0 )
{
$current_user_status = "Online";
}

else
{
$current_user_status = "Offline";
}

$info['current_user_status'] = $current_user_status;



You can then go into the HTML templates for the profile view and use {$info['current_user_status']} wherever you want to echo the user's status.

boeing747fp
10-17-2004, 02:02 AM
didnt work... this is the error now on all profile pages

Fatal error: Call to undefined function: num_rows() in /home/condraft/public_html/boards/sources/Profile.php on line 394

boeing747fp
10-17-2004, 02:15 AM
nvm... i got it to work now... thanks :thumbsup:

kliqster
10-17-2004, 02:36 AM
nvm... i got it to work now... thanks :thumbsup:

Forgot the 'get_' :eek:

Glad you got it sorted anyway. :D

boeing747fp
11-12-2004, 03:40 PM
but how do i get it do take codes where i want them? i have an extension to the Online.php and it keeps putting the stuff at the top instead of where i call it in the skin fike :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum