【发布时间】:2015-03-12 07:54:37
【问题描述】:
我在 php 中创建 pdf 时使用 fpdf,运行时出现此错误:
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
这是我的php代码(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>
另一个(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();
?>
当我输入时:
if(isset($_POST['submitpdf']))
{
$id=$_POST['id'];
//your code goes here
}
错误提示:
Parse error: syntax error, unexpected '$pdf' (T_VARIABLE) in C:\xampp1\htdocs\arvin2\public\pdf2\id.php on line 34
输出应该是在pdf表单中打印的文本字段中输入的所有ID号信息。
【问题讨论】:
-
对于“一些数据已经输出”,您应该确保
<?php ... ?>代码周围没有任何额外的(空格?)字符。对于未定义的索引,看起来您的id表单字段始终为空。 -
小心 SQL 注入。
-
“额外输出”是错误信息,所以通过删除 ID 问题,另一个也会成功
-
没有空格,先生..
-
@AndréDaniel 是的,它总是空着,我该如何解决?