How to Make PDF Invoices From Database in PHP | PHP FPDF Tutorial #example1

preview_player
Показать описание
welcome to php fpdf tutorial example videos.
in this example, i will use invoice from first chapter then combine it with database to make a dynamic invoices.
i have prepared some data beforehand using mock data generator.
there are a lot of websites which provides mock data generation for free. Just google "random data generator".
here is the database design i use in this example.
i have a master table for clients, with clientID as the key.
another table for invoice which contain clientID as a foreign key.
and finally, a table for items of each invoices, using invoiceID as the foreign key.
now let's begin.
first let's make a form page, to select which invoice to be generated.
here we need to get lists of invoices from database so lets make a database connection.
in my case, the database is named "invoiceDB".
make a form with "get" method, and "invoice-db dot php" as action, we will make the file later.
make a dropdown select input named invoiceID.
query the invoices id from database.
then show the result as options.
and don't forget to add submit button.
and the form is done.
now let's make the invoice.
to make things easier, just copy the php file from first chapter and rename it to invoice-db dot php.
add a database connection.
then query the invoice data from invoice table in database.
here we need to inner join clients table using clientID.
and use invoiceID received from GET method in where clause.
and don't forget to fetch the result in an array or object, so we can use it.
now lets replace the previous static invoice data with the dynamic data from database.
now lets display the items.
we need to query the item table in database and use invoiceID in where clause.
and make two variables to hold total tax and total amount.
display the items using where loop, replacing the contents.
we can add thousand separator for numbers using number_format function.
and at the end of each loop, accumulate the total tax and total amount.
finally, display the total amount, total tax, and total due.
this conclude this tutorial video.
thank you for watching, and see you in the next video.

Рекомендации по теме
Комментарии
Автор

Hi, I have come across your channel and this is exactly what I have been looking for! You sir are great. Please may I have the source code for this? I will gladly appreciate it. I have also subbed to your channel. Thanks again.

ZubairPlays
Автор

Hai..salam. I got error as below (for invoice-db.php file):-
1) "Notice: Undefined index: invoiceID in...pdf\invoice-db.php on line 12"
2) "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given...\pdf\invoice-db.php on line 13"

line 12 is: invoiceID = '".$_GET['invoiceID']."'");
line 12 is: $invoice = mysqli_fetch_array($query);

I cannot find what is the problem..

zack-aihtizaz
Автор

can youn plese provide your db file .sql

nishantgholap
Автор

I get the undefined index invoiceID what should i do? seems like the get method doesnt work?

billyandrewmaghirang
Автор

Hello. I have tried this method and i really like it. But for some reason when i pick a invoice in the drop down i get the same data no matter what number i pick. Any obvious reason why?
EDIT: I figured it out. I forgot to use $_GET['InvoiceID'] from the html form. Ty for this guide it was really helpful

SecrethLab
Автор

thanks a lot! One question, how to display image?

itspriyankaaa
Автор

Or can you do coding electricity billing system using php.

joymiegonzales
Автор

Very good tutorials! I watched the whole series and want to start now with the implementation on my male choir website. I want to include mysql data and use the header and footer features. Can you send me the source code? Thanks you in advance.

hermanaben
Автор

Also can you do a tutorial to send data from pdf to mysql database?

dontbeafraid
Автор

While running the code I am getting the error invoice Id is undefined index and some data has already sent...Can you please help me with these errors.!

shrutijain
Автор

$pdf->Cell(130 , 20, 'images/$result['image']', 1, 1); does not work, I don't know how to give the path

itspriyankaaa
Автор

Hi mr Gemul, very nice and instructive tutorial.
Is it possible to add/combine/import a pdf page (obviously non dynamically generated) into the resulting pdf invoices? thanx a lot

vmark
Автор

Best solution i have ever met, I have come across your channel and this is exactly what I have been looking for! Please may I have the source code for this? I will gladly appreciate it.You are really great . please share source code. i will be very grateful.
Thank you

PS-xxvz
Автор

Thank you so much. I need this so much

pikahela
Автор

Please help me. I keep on getting this error message "Notice: Undefined index: invoiceID in on line 12
FPDF error: Some data has already been output, can't send PDF file. What should i do?

nozibusisomarumo
Автор

its a Great Tutorial mam..Please please do it in its my request

ayandas
Автор

Hi again Mr Gemul.
As the tutorial is perfectly working in my local server (localhost) y tried the same in my web hosting server, but it doesn't work there, I have changed all the information regarding the db connection but nothing.
Any idea?

ddimport
Автор

I need help, like you do.
Output : %PDF-1.3 3 0 obj <</Type /Page /Parent 1 0 R /Resources 2 0 R /Contests 4 0 R>> endobj 4 0 obj <<//Filter /FlateDecode /Length 398>> Stream

ravesalways
Автор

How can I use a different size of paper? Is it possible?

cjellal
Автор

Hi mr Gemul, very good tutorial indeed.
I am from Greece so my data contains greek letters than do not appear well in the resulting PDF.
Any idea on how to fix this problem?

ddimport