I'm using fpdf in creating pdf in php and I'm getting this error when running:
Notice: Undefined index: id in C:\xampp1\htdocs\arvin2\public\pdf2\id.php on line 3
FPDF error: Some data has already been output, can't send PDF file
This is my php code (report.php):
<form action="http://localhost/pdf2/id.php" method="post" target="_blank">
<input type="text" name="id">
<input type="submit" name="submitpdf" value="Print"/>
</form>
the other one(eto.php):
<?php
require('mysql_table.php');
$id=$_POST['id'];
class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial','',18);
$this->Cell(0,6,'Type of Leave',0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}
mysql_connect('localhost','root','');
mysql_select_db('auth');
$pdf=new PDF();
//First table: put all columns automatically
$pdf->AddPage();
//Second table: specify 3 columns
$pdf->AddCol('leave_id',20,'','C');
$pdf->AddCol('fullname',40,'Fullname');
$pdf->AddCol('type_of_leave',40,'Type of Leave','R');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$pdf->Table('select leave_id, fullname, type_of_leave from application where id_no="$_POST[id]"',$prop);
$pdf->Output();
?>
When I put:
if(isset($_POST['submitpdf']))
{
$id=$_POST['id'];
//your code goes here
}
The error says:
Parse error: syntax error, unexpected '$pdf' (T_VARIABLE) in C:\xampp1\htdocs\arvin2\public\pdf2\id.php on line 34
The output should be all the info of ID numbers inputted in the text field printed in the pdf form.
put if isset on your code. ie
if(isset($_POST['submitpdf']))
{
//$id=$_POST['id'];
//your code goes here
}
this is to ensure that your code would only run after reading your form-data
EDIT:
your new error i guess comes from the select string.
$pdf->Table('select leave_id, fullname, type_of_leave from application where id_no="$_POST[id]"',$prop);
change it to this:
$pdf->Table("select leave_id, fullname, type_of_leave from application where id_no=".$_POST[id],$prop);