PDF avec valeurs

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

PDF avec valeurs

Post by pasbonte » 2021-04-05 10:41

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;
//}
?>

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: PDF avec valeurs

Post by jsetzer » 2021-04-05 10:46

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

Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: PDF avec valeurs

Post by jsetzer » 2021-04-05 10:56

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 1372 times
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: PDF avec valeurs

Post by jsetzer » 2021-04-05 10:59

chrome_Ha6YrILkAp.png
chrome_Ha6YrILkAp.png (6.44 KiB) Viewed 1372 times
I guess this file will not be found
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: PDF avec valeurs

Post by pasbonte » 2021-04-05 12:16

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;
}
?>


Post Reply