【发布时间】:2020-09-19 08:33:28
【问题描述】:
我不知道为什么没有任何数据显示,它只是显示我硬编码的文件夹数据。但即使数据库有数据,它也不会显示数据库中的任何数据。任何人都可以帮忙吗?我已经想通了一整天,即使这个问题也可能重复,我无法搜索我想要的答案,所以可能需要有人帮助。欣赏。
下面是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.BHD\nCUSTOMER 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,"Complaint\nInitiator",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,"Sales\nOffice",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,"Failure\nSample",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 Details\n(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,"Attachments\n(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 的设计所有它不会显示的数据。有人可以帮忙吗?
【问题讨论】:
-
你测试查询是否正确?
-
了解 sql 注入以及准备和绑定查询的重要性
-
感谢您的回答,我已经解决了在“formselect.php”处选择标签并指定名称为 pdfID 的问题,然后回头查看找到的“generate_pdf.php”我有错字错误,即 pdfId 然后我改回 pdfID 并且它可以工作。