I have created these 2 pages to generate reports.

teller_reports.php

<form id="form1" name="form1" method="post" action="daily_transactions_report.php">
  <label>DailyTransaction Reports<br />
  <br />
  DATE </label>
  <input type="text" id="demo3" name="date" maxlength="25" size="25"/>
  <img src="../images/cal.gif" onclick="javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>
  <p>
    <label></label>
    <label>
    <a href="tcpdf/examples/daily_transactions_report.php">
    <input type="submit" name="button" id="button" value="Generate" />
    </a>
    </label>
  </p>
</form>

daily_transactions.php

<?php

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

    public function myconnection(){
	$this->con = mysql_connect("localhost","root",""); 
	
	mysql_select_db("bank", $this->con);
	
	$date='';
	
    $date = var_dump($_POST['date']);
$this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date = '".$date."' ORDER BY tran_id");

It gives me an error like this.

Notice: Undefined index: date in C:\wamp\www\MySite\php files\tcpdf\examples\daily_transactions_report.php on line 16

line 16 is;

$date = var_dump($_POST['date']);

That's not error.
For checking insert before 17 line:
echo $date;

and see what's on the screen.

same error message displayed.

"null" is also displayed..don't get it as a PDF file..

Try

$date = $_POST['date'];

instead of

$date = var_dump($_POST['date']);

And also make sure date should be in proper format i.e. 20011-08-20

@vibhadevit; i tried this also..But the same error occurs. date format is ok.

It also says,

"TCPDF ERROR: Some data has already been output, can't send PDF file"

hey heshanm,
i don't know if i'm able to help you but you may consider your first post problem as you should not define the variables in object oriented programming like when you are writing in simple php.. i'll chang your code to be more efficient and try it so you may get a good result

PHP Syntax (Toggle Plain Text)

    <?php
     
    require_once('../config/lang/eng.php');
    require_once('../tcpdf.php');
     
    // extend TCPF with custom functions
    class MYPDF extends TCPDF {
     public $date;
     
    public function myconnection(){
    $this->con = mysql_connect("localhost","root","");
     
    mysql_select_db("bank", $this->con);
     
    $date='';
     
    $date = var_dump($_POST['date']);
    $this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date = '{$date}' ORDER BY tran_id");

and i noticed that you may have a problem with the result or i'm just not familiar with the tcpdf code but i know when we wirte $this->result and result is not a function ( i mean it's a variable) it should be written like this $this->$result
and the same for con.... beside if they are already inherited from the extended class it's okay not to mention it in the public scope but if not you should define it just like i defined th $date variable

hey mamdouh ramadan; I have tried your codings. But nothing happens. Same error exists.

In TCPDF, there are default php codings. I only changed the query according to my requirement.

When i amend your suggestions further error messages arise such as

Undefined variable: con in C:\wamp\www\MySite\php files\tcpdf\examples\daily_transactions_report.php on line 10

Fatal error: Cannot access empty property in C:\wamp\www\MySite\php files\tcpdf\examples\daily_transactions_report.php on line 10

add this on the top of your page

error_reporting(0);

i do that if some notices or warnings occurs.

hey mamdouh ramadan; I have tried your codings. But nothing happens. Same error exists.

In TCPDF, there are default php codings. I only changed the query according to my requirement.

When i amend your suggestions further error messages arise such as

Undefined variable: con in C:\wamp\www\MySite\php files\tcpdf\examples\daily_transactions_report.php on line 10

Fatal error: Cannot access empty property in C:\wamp\www\MySite\php files\tcpdf\examples\daily_transactions_report.php on line 10

hey again,
to justify what i was saying....
there is nothing in php written in this way

$this->con

because con is not a method, it's a variable so, if it's inherited you simply should add the $ sign like this

$this->$con

if it's not inherited so you should define it in public scope like this

public $con;

@ Rhamises ; Now it displays "null". I have entered the date where actual transaction have taken place. But "null" is coming.

@ mamdouh ramadan;But it shows the above error message

I think your post is not proper so write following code at line 15, and check what all is posted to your script.

Also copy intialise $date directly without using var_dump

echo "<pre>";
print_r($_POST);
echo "</pre>";

$date =$_POST['date'];
echo $date;

@urtrivedi ; It generates the following output.

Array
(
)

@heshanm i'm really sorry but i think i can help you more if you just paste the TCPDF class here so i can understand what the main problem.
and belive me this kind of problems would never last for more than two minutes :D

sorry for being late

@mamdouh ramadan ; The 2 pages i have posted at the very begining are the ONLY codings that i have regarding this report generation problem

Seperately i have installed TCPDF software.

Hi,

I have amended the coding little bit. Now it generates an EMPTY REPORT. All the fields are there in the record. But no records were displayed relevant to the particular date.

<?php

error_reporting();

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

public function myconnection(){
$this->con = mysql_connect("localhost","root",""); 
	
mysql_select_db("bank", $this->con);
	
if(isset($_POST['date']))
    $date=$_POST['date'];
else
    $date='';
	
	
$this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date = '".$date."' ORDER BY tran_id");
	
	
}
Array
(
)

It means your page is not receiving post values. so check the html or the page which is calling your report page.

User die() instead of mysql_query, run that query in sql in phpmyadmin and find the error , its better to find the error than solution.

Post the html code where you have form fields.

This is my HTML form.

<form id="form1" name="form1" method="post" action="tcpdf/examples/daily_transactions_report.php">
  <label>DailyTransaction Reports<br />
  <br />
  Transaction Date</label>
  <input type="text" id="demo3" name="date" maxlength="25" size="25"/>
  <img src="../images/cal.gif" onclick="javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/>
  <p>
    <label></label>
    <label>
    <a href="tcpdf/examples/daily_transactions_report.php">
    <input type="submit" name="button" id="button" value="Generate" />
    </a>
    </label>
  </p>
</form>

The date is picked from a calender

Oh.. i forget you already posted html code on first post..
Can you try below one..
Use any static date which is there in database and post output..

<?php

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

    public function myconnection(){
	$this->con = mysql_connect("localhost","root",""); 
	
	mysql_select_db("bank", $this->con);
	
	$date = '2011-08-11'; // use any date which is there in database
$this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date = '".$date."' ORDER BY tran_id") or die( '<strong>Error: </strong>'. mysql_errno().':'.mysql_error());

@vibhadevit : Now data coming when i entered a date which exist in a database....:-)

I think there is something wrong with DATE format...???

Problem is in your first form it is not posting values properly

Thanks everyone..I have corrected my HTML form and now it is working properly..:-)

But there is another small issue.

For an example let's say for a given date i have 2 transactions in my database. When they display in the report, the 2 nd transaction or the second row is not coming after 1st row. It is coming horizontally outside the table and not visible to anyone.

Can anyone give me a solution? I have posted the full working code.

<?php

error_reporting();

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

    public function myconnection(){
	$this->con = mysql_connect("localhost","root",""); 
	
	mysql_select_db("bank", $this->con);
	
   
   $date='';
	
   $date=$_POST['date'];
	
	
$this->result = mysql_query("SELECT * FROM transaction WHERE transaction_date = '".$date."' ORDER BY tran_id") or die ('<strong>Error:</strong>'.mysql_errno().':'.mysql_error());
	
}

	// Colored table
	public function ColoredTable($header,$data) {
		// Colors, line width and bold font
		$this->SetFillColor(200, 128, 0);
		$this->SetTextColor(255);
		$this->SetDrawColor(128, 0, 0);
		$this->SetLineWidth(0.3);
		$this->SetFont('', 'B');
		// Header
		$w = array(18, 15, 32, 22, 30, 45);
		$num_headers = count($header);
		for($i = 0; $i < $num_headers; ++$i) {
			$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
		}
		$this->Ln();
		// Color and font restoration
		$this->SetFillColor(200, 200, 200);
		$this->SetTextColor(0);
		$this->SetFont('');
		// Data
		$fill = 0;
		while($row1 = mysql_fetch_array($this->result))
 		{
			$this->Cell($w[0], 6, $row1['tran_id'], 0, 'L', $fill);
			$this->Cell($w[1], 6, $row1['account_number'], 'LR', 0, 'R', $fill);
			$this->Cell($w[2], 6, $row1['transaction_type'], 'LR', 0, 'L', $fill);
			$this->Cell($w[3], 6, $row1['transaction_amount'], 'LR', 0, 'L', $fill);
			$this->Cell($w[4], 6, $row1['transaction_date'], 'LR', 0, 'L', $fill);
			$this->Cell($w[5], 6, $row1['approved_status'], 'LR', 0, 'L', $fill);
			$fill=!$fill;
		}
		$this->Cell(array_sum($w), 0, '', 'T');
	}
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Mahapitiya Sanasa Bank');
$pdf->SetTitle('Daily Transaction Report');
$pdf->SetSubject('');
$pdf->SetKeywords('');

// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 011', PDF_HEADER_STRING);

// set header and footer fonts
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'BI', 7);

// add a page
$pdf->AddPage();

// set some text to print
$txt = <<<EOD
Mahapitiya Sanasa Bank,
Mahapitiya,
Pothuhera
Tel:0372237295

Daily Transactions Report 


EOD;

// print a block of text using Write()
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);


//Column titles
$header = array('Tran ID', 'Account Number', 'Transaction Type', 'Transaction Amount', 'Transaction Date', 'Approved Status');

//Data loading
//$data = $pdf->LoadData('../cache/table_data_demo.txt');
$pdf->myconnection();

// print colored table
$pdf->ColoredTable($header,"");

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_011.pdf', 'I');
mysql_close($con);
?>
//============================================================+
// END OF FILE                                                
//============================================================+

Once your first row is displayed second row should be in next line.
something like

<?
		$rowCnt = 6;
		while($row1 = mysql_fetch_array($this->result))
 		{
			$this->Cell($w[0], $rowCnt, $row1['tran_id'], 0, 'L', $fill);
			$this->Cell($w[1], $rowCnt, $row1['account_number'], 'LR', 0, 'R', $fill);
			$this->Cell($w[2], $rowCnt, $row1['transaction_type'], 'LR', 0, 'L', $fill);
			$this->Cell($w[3], $rowCnt, $row1['transaction_amount'], 'LR', 0, 'L', $fill);
			$this->Cell($w[4], $rowCnt, $row1['transaction_date'], 'LR', 0, 'L', $fill);
			$this->Cell($w[5], $rowCnt, $row1['approved_status'], 'LR', 0, 'L', $fill);
			$fill=!$fill;
			$rowCnt++ ;
		}
?>

I think you must give 1 after LR for last cell only, so that next character will be printed on new line.

$this->Cell($w[5], 6, $row1['approved_status'], 'LR', 1, 'L', $fill);

@urtrivedi : It works fine..Thanks a lot..:-)

Thanks all of you for helping me to solve this problem...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.