Page 1 of 1

PDF avec valeurs

Posted: 2021-04-05 10:41
by pasbonte
hello

I finally could put a button
Call FPDF and create a PDF page with "hello world"
Now I would like to print with values

I have:

http: //.........atest5.php? SelectedID = 38


But then in this code, how to find this value ID = 38?

Code: Select all

<? php

// include (dirname (__ FILE__). '/../../../lib.php');
// require (dirname (__ FILE__). 'fpdfh.php');
require ('xxxxxxxxxx / fpdf / fpdf.php');

$ results = print_item_query ($ id);

$ pdf = new PDF_HTML ();
$ pdf-> AddPage ();
$ pdf-> SetFont ('Times', 'B', 14);
$ pdf-> Cell (0,10, 'Item:'. $ results ['id'], 1,1);
// $ pdf-> Cell (0,10, 'Description:'. $ results ['description'], 1,1);
$ pdf-> Output ();
exit;
//}
?>

Re: PDF avec valeurs

Posted: 2021-04-05 10:46
by jsetzer

Code: Select all

$id = $_REQUEST["SelectedID"];
For security reasons, always check what people have posted before using it, especially before using arguments in SQL statements (danger of SQL-injection). You can use the makeSafe() function for this.

I prefer something like this:

Code: Select all

// (not tested)
// you have to include lib.php before using makeSafe or other AppGini related functions

$id = isset($_REQUEST["SelectedID"]) ? makeSafe($_REQUEST["SelectedID"]) : null;
$record = $id ? getRecord("TABLENAME", $id) : null;

if ($record) {
	// get data from $record array
	// create and output your PDF
} else {
	// some error handling (record not found)
}

// instead of using getRecord function, you can also use sqlValue() or sql() function for fetching data


Re: PDF avec valeurs

Posted: 2021-04-05 10:56
by jsetzer
I'd like to recommend you should remove and avoid extra spaces as they may lead to syntax errors and unexpected interpretation by the PHP interpreter.
chrome_Zk9qyHD6Ct.png
chrome_Zk9qyHD6Ct.png (17.31 KiB) Viewed 2316 times

Re: PDF avec valeurs

Posted: 2021-04-05 10:59
by jsetzer
chrome_Ha6YrILkAp.png
chrome_Ha6YrILkAp.png (6.44 KiB) Viewed 2316 times
I guess this file will not be found

Re: PDF avec valeurs

Posted: 2021-04-05 12:16
by pasbonte
thank you I advance, I am a beginner ..
I have deleted the spaces, thank you, before securing I am doing tests ..

I suppose that to have all the fields you have to make a loop ...

concerning the path it is to hide .. it is not the right code ..

I knew how to do it 10 years ago .. but I forgot lol

Code: Select all

<? php

// include (dirname (__ FILE__). '/../../../lib.php');
// require (dirname (__ FILE__). 'fpdfh.php');
require ('/xxxxxxxx/ fpdf/fpdf.php');

$id =$ _REQUEST ["SelectedID"];

$query = "select * from DEBIT_HSE WHERE` id` = '". $ _ REQUEST [' id ']."' ";
$result = mysql_query ($ query);

// display

while ($ row = mysql_fetch_array ($ result))
  {
$ pdf = new FPDF ();
$ pdf-> AddPage ();
$ pdf-> SetFont ('Times', 'B', 14);
$ pdf-> Cell (50,10, 'Item:'. $ id, 10,10);
$ pdf-> Cell (50,10, 'NAME:'. $ id, 10,10);
// $ pdf-> Cell (0,10, 'Description:'. $ results ['description'], 1,1);
$ pdf-> Output ();
// exit;
}
?>