gpt4 book ai didi

php - fpdf错误和查看表错误

转载 作者:行者123 更新时间:2023-11-27 23:34:21 25 4
gpt4 key购买 nike

enter image description here

 $sqlinsert="SELECT * FROM imagetable "; 
$result = mysqli_query($con, $sqlinsert);

echo "<table border='1'>";
echo "<tr>
<th>ID</th>
<th>School Code</th>
<th>Category</th>
<th> School name </th>
<th> School Address </th>
<th> School name </th>

</tr>";

while($row = mysqli_fetch_assoc($result)){
$id= $row['ID'];
echo "<tr>
<td>";
echo $row['ID'];
echo "<td>";
echo $row['category'];
echo "<td>";
echo $row['sname'];
echo "<td>";
echo $row['sadd'];
echo "<td>";
echo $row['filename'];

echo "<td>";
?>


<form name="form" method="POST" action="parentssubmit.php">
<input type="hidden" value="<?php echo $id;?>" name="search">
<input type="submit" value="View" name="View">
</form>
<?php }

echo "</td></tr>";
echo "</table>";
========================================================================
if (isset($_POST['View']) ){
$pdf=new fpdf();
$pdf->ADDPage();
$pdf->setfont('Arial','B', 16);
$pdf->Cell(40,10, 'sname',1,0,'c');
$pdf->Cell(40,10, 'sadd',1,0,'c');
$pdf->Cell(40,10, 'category',1,0,'c');
$pdf->Cell(40,10, 'scode',1,0,'c');


$con = mysqli_connect("localhost","root","","school");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


$file_filename=$_FILES['file']['name'];

$target_path = "Newfolder1";


$image_path = $target_path . DIRECTORY_SEPARATOR . "filename";

$image_format = strtolower(pathinfo('filename', PATHINFO_EXTENSION));
$sql="SELECT * FROM imagetable WHERE ID= '$_POST[search]'";
$result = mysqli_query($con, $sql);
if(!mysqli_query($con, $sql)){
die( "Could not execute sql: $sql");
}

// build the data array from the database records.
While($row = mysqli_fetch_array($result)) {
$pdf->Cell(40,10, $row['sname'],1,0,'c');
$pdf->Cell(40,10, $row['sadd'],1,0,'c');
$pdf->Cell(40,10, $row['category'],1,0,'c');


$pdf->Image($image_path,50,100,50,20,$image_format);

$pdf->ln();}
}
$pdf->output();

这是两个页面,出现错误未定义索引:

文件未定义索引:文件所以请尝试指出错误,因为当我添加图像字段时显示主要错误,然后错误开始弹出。

  • 我正在尝试从数据库中获取图像并尝试以 PDF 格式显示它。

最佳答案

首先,您应该关闭所有 <tr><td>标签。其次,您没有随表单发送任何文件,因此您得到了这个 Undefined index: file错误,所以删除这些行,

$file_filename=$_FILES['file']['name'];
$target_path = "Newfolder1";
$image_path = $target_path . DIRECTORY_SEPARATOR . "filename";
$image_format = strtolower(pathinfo('filename', PATHINFO_EXTENSION));

所以在用户点击 view 之后按钮,你应该像这样处理你的表单和显示图像,

// your code

if (isset($_POST['View']) ){
$pdf=new fpdf();
$pdf->ADDPage();
$pdf->setfont('Arial','B', 16);
$pdf->Cell(40,10, 'sname',1,0,'c');
$pdf->Cell(40,10, 'sadd',1,0,'c');
$pdf->Cell(40,10, 'category',1,0,'c');
$pdf->Cell(40,10, 'scode',1,0,'c');


$con = mysqli_connect("localhost","root","","school");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT * FROM imagetable WHERE ID= '$_POST[search]'";
$result = mysqli_query($con, $sql);
if(!mysqli_query($con, $sql)){
die( "Could not execute sql: $sql");
}

$row = mysqli_fetch_array($result);
$image_path = $row['file'] . DIRECTORY_SEPARATOR . $row['filename']; // path should be like this, process/upload/8/cdv_photo_001.jpg
$image_format = strtolower(pathinfo($image_path, PATHINFO_EXTENSION));
$pdf->Cell(40,10, $row['sname'],1,0,'c');
$pdf->Cell(40,10, $row['sadd'],1,0,'c');
$pdf->Cell(40,10, $row['category'],1,0,'c');
$pdf->Image($image_path,50,100,50,20,$image_format);
$pdf->ln();
$pdf->output();
}

// your code

关于php - fpdf错误和查看表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34475345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com