数据未使用php以pdf格式显示



我不知道为什么没有任何数据显示,只是显示我硬编码的文件夹数据。但即使数据库有数据,它也不会显示数据库中的任何数据。有人能帮忙吗?我已经想了一整天了,甚至这个问题可能重复,我无法搜索我想要的答案,所以可能需要别人的帮助。欣赏

以下是pdf调用"generate_pdf.php"的代码

<?php
require_once 'config.php';
require 'fpdf181/fpdf.php';
$query=mysqli_query($conn,"select * from images where Id = '".isset($_POST['pdfId'])."'");
$gpdf=mysqli_fetch_array($query);
$id = $gpdf['Id'];              //"ID";
$txt = $gpdf['CompanyN'];       //"Kamaya";
$txt2 = $gpdf['ContactP'];      //"Sales";
$txt3 = $gpdf['Email'];         //"sss@kamaya.com.my";
$chk = $gpdf['checkbox'];       //"KJ";
$chk1 = $gpdf['Others'];        //"Others";
$txt5 = $gpdf['Othersinput'];   //"Others";
$txt6 = $gpdf['SalesStaff'];    //salesstaff
$txt7 = $gpdf['LotNo'];         //"886515154M";
$txt8 = $gpdf['CusPartNo'];     //"cus123456";
$txt9 = $gpdf['Title'];         //"cannot work";
$chk2 = $gpdf['checkbox2'];
$chk9 = $gpdf['process'];
$txt10 = $gpdf['inputbox2'];    //"JIG STACKING";
$chk10 = $gpdf['Others2'];
$txt24 = $gpdf['Othersinput2'];
$txt11 = $gpdf['Rate'];         //"10%";
$txt12 = $gpdf['FailDate'];     //"2020-09-06"; 
$chk3 = $gpdf['checkbox3'];     //"return";
$txt14 = $gpdf['ETA'];          //"2020-09-06";
$txt15 = $gpdf['Quantity'];     //"5";
$chk4 = $gpdf['checkbox4'];     //"No required";
$txt17 = $gpdf['ETD'];          //"2020-09-06";
$txt18 = $gpdf['Quantity2'];    //"5";
$chk5 = $gpdf['checkbox5'];     //"required";
$chk6 = $gpdf['Method'];        //"Phone";
$txt19 = $gpdf['VisitBy'];      //"me";
$txt20 = $gpdf['visitDate'];    //"2020-09-06";
$txt21 = $gpdf['Reportdate'];   //"2020-09-06";
$txt22 = $gpdf['Textarea'];     //"qqwweerrttyyuuiiooppllkkjjhhggffddssaazxxzxccvvbnm.,lpiujhhhgvasgvybagfvabfvgyabuibaubfvuigaubvuailbuaubkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk";

$pdf = new FPDF();
$pdf->AddPage('P','A4',0);

$pdf->SetFont('Arial','B',9);
//$pdf->SetXY(7,5);
$pdf->Multicell(120,5,"KAMAYA ELECTRIC (M) SDN.BHDnCUSTOMER COMPLAINT SHEET",1,"C");

$pdf->SetXY(130,10);
$pdf->Multicell(69,5,"Date Issued :".date('yy-m-d'),1,"C");

$pdf->SetXY(130,15);
$pdf->Multicell(69,5,"Report No :".$id,1,"C");

$pdf->Multicell(26,7.5,"ComplaintnInitiator",1,"C");

$pdf->SetXY(36,20);
$pdf->Multicell(163,5,"Co.Name :".$txt,1);

$pdf->SetXY(36,25);
$pdf->Multicell(163,5,"Contact Person: ".$txt2,1);

$pdf->SetXY(36,30);
$pdf->Multicell(163,5,"Email / Contact No: ".$txt3,1);

$pdf->Multicell(26,7.5,"SalesnOffice",1,"C");

$pdf->SetXY(36,35);
$pdf->Multicell(163,5,$chk,1);

$pdf->SetXY(36,40);
$pdf->Multicell(163,5,$chk1." ".$txt5,1);

$pdf->SetXY(36,45);
$pdf->Multicell(163,5,"Sales Staff : ".$txt6,1);

$pdf->Multicell(26,10,"Product",1,"C");

$pdf->SetXY(36,50);
$pdf->Multicell(163,5,"Lot No : ".$txt7,1);

$pdf->SetXY(36,55);
$pdf->Multicell(163,5,"Customer Part No : ".$txt8,1);

$pdf->Multicell(26,15,"Failure",1,"C");

$pdf->SetXY(36,60);
$pdf->Multicell(163,5,"Title : ".$txt9,1);

$pdf->SetXY(36,65);
$pdf->Multicell(163,5,"Scene : ".$chk2." t ",1);

$pdf->SetXY(36,65);
$pdf->Write(5,$chk9. "" . $txt10);

$pdf->SetXY(36,65);
$pdf->Write(5,$chk10. "" . $txt24);

$pdf->SetXY(36,70);
$pdf->Multicell(163,5,"Rate : ".$txt11." t "."Date :".$txt12,1);

$pdf->Multicell(26,7.5,"FailurenSample",1,"C");

$pdf->SetXY(36,75);
$pdf->Multicell(163,8,$chk3." t "."ETA :".$txt14,1);

$pdf->SetXY(36,83);
$pdf->Multicell(163,7,"Quantity :".$txt15,1);

$pdf->Multicell(26,15,"Replacement",1,"C");

$pdf->SetXY(36,90);
$pdf->Multicell(163,8,$chk4." t "."ETD :".$txt17,1);

$pdf->SetXY(36,98);
$pdf->Multicell(163,7,"Quantity :".$txt18,1);

$pdf->Multicell(26,15,"Reply",1,"C");

$pdf->SetXY(36,105);
$pdf->Multicell(163,5,$chk5."t Method : ".$chk6,1);
$pdf->SetXY(36,110);
$pdf->Multicell(163,5,"Visit By : ".$txt19."t Date : ".$txt20,1);
$pdf->SetXY(36,115);
$pdf->Multicell(163,5,"Report Required Date : ".$txt21,1);

$pdf->Multicell(26,15,"Failure Detailsn(Attached photo if available)",1,"C");

$pdf->SetXY(36,120);
$pdf->Multicell(163,5,$txt22,1);

//display image and document
$temp = "37";
$temp2 = "154";
$temp3 = "51";
$temp4 = "185";
$imgrow=0;
$allFiles1 = scandir("F:/xampp/htdocs/new3/uploads/KM2009001");
$files1 = array_diff($allFiles1, array('.', '..')); // To remove . and .. 
foreach($files1 as $file1)
{
$tt = "F:/xampp/htdocs/new3/uploads/KM2009001"."/".$file1;

if(is_file($tt)){
$allowed = array('gif', 'png', 'jpg');
$ext = pathinfo($tt, PATHINFO_EXTENSION);
if (in_array($ext, $allowed)) {
$imgrow ++;
$pdf->SetXY(37,154);
if($imgrow === 1)
{
$pdf->Image($tt,$temp,$temp2,30,20);
$temp+=40;
}
$imgrow=0;
}
else
{
$pdf->SetXY($temp3,$temp4);
$file = basename($tt,$file1);
$pdf->DisplayPreferences('DisplayDocTitle');
$pdf->Write(5,$file);
$temp4 += 5;

}

}
}
$pdf->Line(36,180,199,180);
$pdf->Line(199,180,199,120);
$pdf->SetXY(10,180);
$pdf->Multicell(26,15,"Attachmentsn(if available)",1,"C");
$pdf->SetXY(36,180);
$pdf->Multicell(15,5," NO ",1,"C");
$pdf->SetXY(36,185);
$pdf->Multicell(15,5," 1 ",1,"C");
$pdf->SetXY(36,190);
$pdf->Multicell(15,5," 2 ",1,"C");
$pdf->SetXY(36,195);
$pdf->Multicell(15,5," 3 ",1,"C");
$pdf->SetXY(36,200);
$pdf->Multicell(15,5," 4 ",1,"C");
$pdf->SetXY(36,205);
$pdf->Multicell(15,5," 5 ",1,"C");
$pdf->SetXY(51,180);
$pdf->Multicell(148,5,"Attachments",1,"C");
$pdf->SetXY(51,185);
$pdf->Multicell(148,5,"",1,"C");
$pdf->SetXY(51,190);
$pdf->Multicell(148,5,"",1,"C");
$pdf->SetXY(51,195);
$pdf->Multicell(148,5,"",1,"C");
$pdf->SetXY(51,200);
$pdf->Multicell(148,5,"",1,"C");
$pdf->SetXY(51,205);
$pdf->Multicell(148,5,"",1,"C");

$pdf->Output();
?>

这是一个可以选择ID并通过点击生成按钮"formselect.php"生成PDF的表单

<?php
require 'config.php';
?>
<html>
<head>
<title>8D Generator</title>
</head>
<body>
<form method='POST' action='generate_pdf.php'>
<select name='pdfID'>
<?php
$query=mysqli_query($conn,'select * from images');
while($gpdf=mysqli_fetch_array($query))
{
echo "<option value='".$gpdf['Id']."'>".$gpdf['Id']."</option>";
}
?>
</select>
<input type='submit' value='Generate'>
</form>
</body>
</html>

它应该以pdf格式显示,但现在输出只显示pdf的设计——它不会显示的所有数据。有人能帮忙吗?

首先,您必须更正这一行(请参阅@Simone Rossaini评论(:

/* error:
$query=mysqli_query($conn,"select * from images where Id = '".isset($_POST['pdfId'])."'");
*/

因为isset((函数返回一个CCD_ 1(true或false(。因此,您的查询永远不会工作,因为Id将无效。(Id应该是字符串或int,对吧?(

将查询更改为以下内容:

$pdf_id = isset($_POST['pdfId']) ? mysqli_real_escape_string($conn, $_POST['pdfId']) : "";
if (empty($pdf_id)) {
// no id was given -> alert the user
die('Error: no id!');
}
$query=mysqli_query($conn,"select * from images where Id = '".$pdf_id."'");

它起作用了吗?在运行查询后尝试添加var_dump($gpdf);,以检查是否获得了正确的数据。

最新更新