2

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.

Isma
  • 14,604
  • 5
  • 37
  • 51
Dr.MTR
  • 207
  • 7
  • 19

1 Answers1

2

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

wesamly
  • 1,484
  • 1
  • 16
  • 23