Jump to content

PHP in tpl files


BAJI26

Recommended Posts

I would like to add some php on the header.tpl and footer.tpl to display some info from the DB. I tried {php} but its giving some errors. What would be the best way to add it?

 

<?php 
					require("init.php");
					require("includes/functions.php");
					if ($_SESSION['uid'])
					{
    						$query="SELECT * FROM tbl** WHERE id='" .sanitize($_SESSION['**']) . "'";
						$result = mysql_query($query) or die(mysql_error());
						if($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
						{
?>

Link to comment
Share on other sites

Yea and it messed the page, it actually removed the entire footer.

if you were using it on a page within your whmcs site, e.g footer or header, you should remove the 'members' bit of the first line.

 

require_once 'init.php';

if you do that, it should work - I just pasted that code into six/footer.tpl and it works fine - if that path is wrong, it blank the screen.

 

that said, as sentq suggested, you'd probably be better off using an action hook (or data feed) - i'd avoid using {php} in the templates now unless absolutely necessary.

 

with a data feed, you really only need to know two things - the SQL query and how you want to display the output - you say you already have the query, and you know how you want it to look, so it should be relatively straightforward to create the feed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated