Error when rendering .tpl file from SQL query

455 Views Asked by At

I'm trying to get a result from a MySQL database and display selected values into a .tpl template file.

This is what I tried so far:

{php}
$clienthosting = $this->get_template_vars(service);//Here is where the exception is thrown
$dbid = $clienthosting['id'];  
$query = mysql_query("SELECT dedicatedip FROM tblhosting WHERE id = $dbid");  
$result = mysql_fetch_array($query); 
$dedicatedip = $result["dedicatedip"];   
$this->assign("dedicatedip", $dedicatedip); 
{/php} 

But it generated the following error:

Something went wrong and we couldn't process your request.

What am I doing wrong?

Thanks.

1

There are 1 best solutions below

2
wesamly On

WHMCS recommends not use {php} inside tpl files, you can use hooks instead to add variables and use them in the TPL file.

But you can enable it in the settings: Setup > General Settings > Security > Allow Smarty PHP Tags.

Also, if you're running PHP 7 the mysql extension is removed, you can't use functions like mysql_query and mysql_fetch_array.

You should use Capsule and Eloquent as recommended at Interacting with the Database page