Search code examples
phpfootertcpdf

Custom footer text using TCPD php


I tried to make a custom text in footer TCPD and put variable that i already defined from database which is '$name'. But it keeps get error said 'Notice: Undefined variable: name'.

public function Footer() {
        
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        
        $fhtml = '
        <table>
        <tr>
        <td>User </td><td colspan="10">: '.$name.'</td>
        
    </tr>
    </table>
    ';
    
    $this->writeHTML($fhtml, true, false, true, false, '');

    }

and this variable that i already defined

$user = mysqli_query($conn,"SELECT * FROM users WHERE users='$users'");
$sqluser = mysqli_fetch_assoc($user);
$name = $sqluser["login"];

How can i make a custom footer TCPDF


Solution

  • This issue is not related to TCPDF but related to PHP. You are using a global variable inside the scope of the class method.

    Modify the class method to redefine the scope of the $name variable inside the method as follows

    public function Footer() {
      global $name
      ....
    }