Page 1 of 1

TCPDF - GET ID

Posted: 2023-01-24 22:36
by dgniewek
Hello !
I'm really desperate now and I don't know what to do.
I am trying to implement a PDF generation function in my project - using the TCPDF library.
I can't get ID to copy the variables to my PDF from the table data.
Do you know how I can get the ID from "dv"?

Here I am posting the current code to get the ID - which is not working
Thanks for any advice!

Code: Select all

 
 // Include the main TCPDF library (search for installation path).
require_once '/www/login/vendor/tecnickcom/tcpdf/tcpdf.php';

//1) Připojení k databázi
$mysqli = new mysqli("localhost", "username", "pass", "db");

//3) Načtení ID z POST nebo GET metody
$pk = $_POST['id'] ?? $_GET['id'] ?? $data['selectedID'];

//4) Načtení proměnných z aktuálního záznamu
$query = "SELECT * FROM objednavky WHERE id = '$pk'";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$firma = $row['firma'];
$kontaktni_osoba = $row['kontaktni_osoba'];
$email = $row['email'];
$platce_ico = $row['platce_ico'];
$email = $row['cena_hod'];
 

Re: TCPDF - GET ID

Posted: 2023-01-25 06:05
by jsetzer
What is the current value of $pk?

When executing your script from DV, are you passing id as parameter?

How do you call the script?

Re: TCPDF - GET ID

Posted: 2023-01-25 14:40
by dgniewek
Sorry, I posted the wrong code with the $pk value.
I'm trying to get the ID of the record to generate the variables just like this:

Code: Select all

//3) Načtení ID z POST nebo GET metody
$id = $_GET['id'];

//4) Načtení proměnných z aktuálního záznamu
$query = "SELECT * FROM objednavky WHERE id = '$id'";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$firma = $row['firma'];
$kontaktni_osoba = $row['kontaktni_osoba'];
$email = $row['email'];
$platce_ico = $row['platce_ico'];
$email = $row['cena_hod'];
The scenario is that the user clicks on the "Download PDF" button in the appgini "DV" web application and the script would then retrieve the data from the database based on the ID that was passed as a parameter and create a PDF with that data.

Re: TCPDF - GET ID

Posted: 2023-01-25 15:27
by jsetzer
So, if you already have managed...

1. To create the button in DV,
2. on click, open your script and pass selectedID as id parameter in URL
3. and to get the correct ID from $_GET into $id variable

...then what is the problem?

If you need to get the record's primary key (PL) in DV you can use Javascript and get .val() from <input name="SelectedID" ...>

Re: TCPDF - GET ID

Posted: 2023-01-25 22:36
by D Oliveira
you shouldn't be executing a query with this get request parameter without the makeSafe() function shielding from a mysql injection.