MyBB Community Forums

Full Version: PHP In Templates Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok so I installed the PHP in templates plugin for my forums. While trying to add some PHP into the files it worked.
This is my PHP Code:
<?php
mysql_connect("localhost", "mysqluser", "mysqlpass") or die(mysql_error());
mysql_select_db("mysqldatabase") or die(mysql_error());
$online = mysql_query("SELECT * FROM online  WHERE id = 1");
$totalonline = mysql_fetch_array($online);
?>

How I am using it:
<center>There are currently <FONT COLOR="#00FF00">$totalonline</font> players playing CarnagePk!

How it is turning out on the website:
[Image: SWwDq6c.png]



Any help would be greatly appreciated. Thank you!

PS- All MySQL info has been changed Toungue
As you should have noticed, to output variable in a template you need to put it in curly brackets. So it should be <FONT COLOR="#00FF00">{$totalonline}</font>.

Next thing - what are you exactly trying to accomplish? $totalonline is array so your result is not surprising. If you want to output any element from array, you need to do it like this (let's say playername is column in your db): {$totalonline['playername']} Of course you also should maintain security and use htmlspecialchars_uni or whatever on it before output. Additionally I'm quite sure you want to make fetch_array looped.

And lastly, not connected to this problem, <center> and <font> shouldn't be used anymore. They are deprecated.