Using FPDF with webhost

I have created a very complex site in php on my pc which is running WAMP, which is working perfectly. I have uploaded the site to my webhost, setup the MySQL database and edited to suite the webhost. All is now working except the PDF reports generated.

I have created a very simple report that gives a message 'Hello World" followed by a list from a table in MySQL. I get the page with only the “Hello World” on it. I’ve tried various different things but it won’t access the database.

Can anyone please, please, please help me?

What happens? Are you running the same versions of PHP on WAMP and on your webhost?

I’ll check…

Oh, nooooo. My pc is on 5.5.12 & the host is on 5.4 24

Do you think this could be the problem with accessing the database?

As to what happens, I can save changes to the db and I can print a report that doesn’t access the database but it won’t include anything from the db.

I get lists from the db in plain php. But only text when I use FPDF,

It might be worth checking on the FPDF documentation for the version you’re using and see if it insists on a minimum version of PHP to work successfully.

Edit: Actually, it looks like PHP5.1 should be good enough for the current version, so that’s not likely to be your problem - http://www.fpdf.org/

The webhost is on 5.4, but even with this, I get a pdf. It just won’t access the data from the DB and put it on the form.

So, to be clear, is the problem accessing the database or printing the PDF? Maybe you also need to check the versions of MySQL you have on your WAMP installation and the live system.

1 Like

Mine’s 5.6 & their’s is 5.5 - Can’t see what version FPDF prefers.

I get a “Hello World” on the pdf for the pdf is actually working. It’s just not getting any info from the database and putting it on the page.

1 Like

Probably need to see some of the code to be any help. Is it not getting any info from the database, or not putting it on the page?

1 Like

Here’s the code:

<?php

// Create a connection to the postaldb database
// Set the database access details as constants and set the encoding to utf-8
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', 'xxx');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'finalpost');
// Make the connection
$conn = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die
('Could not connect to MySQL: ' . mysqli_connect_error() );

$query = "SELECT * from inc"; 
$result = mysqli_query($conn, $query) or die(mysqli_error());

require('../fpdf/fpdf.php');

$pdf = new FPDF('L','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->Cell(40,12,'Hello World',1);

foreach($result as $row) {
//	$pdf->SetFont('Arial','',12);	
	$pdf->Ln();
	foreach($row as $column)
		$pdf->Cell(20,12,$column,1);
}

$pdf->Output();
?>

Here’s a screenshot of what I get on my PC:

And here’s what I’m getting from the webhost:

Both are using the code above.

1 Like

That looks like an issue with the query not the PDF library. Remove the error suppression symbol from mysqli_connect and see if it emits any errors.

If you are going to use error suppression you should at least check the process didn’t fail and handle the error appropriately.

1 Like

Sorry, I’m very new to this. Can you please show me which portion I should remove?

$conn = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME

to

$conn = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME

1 Like

@ Suppresses errors

1 Like

I’ve done that and still don’t get an error message

Is the inc table empty?

The behavior you’re describing indicates the inc table is empty.

No, it has 76 rows of data in it

My guess is PHP is using “echo” but fpdf needs a “return”, let me check the documentation.

EDT
I think I was out in the left field bleachers

Right after this put in print_r($result); exit;
this will tell you if you are really getting data.

1 Like

It now gives me this:

mysqli_result Object ( )

This tells me the query is empty, try this link, it may help.

your print_r should look similar to
mysqli_result Object ( [current_field] => 0 [field_count] => 2 [lengths] => [num_rows] => 0 [type] => 0 )

1 Like