fpdf错误和查看表错误 [英] fpdf error and view table error
本文介绍了fpdf错误和查看表错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ sqlinsert =SELECT * FROM imagetable;
$ result = mysqli_query($ con,$ sqlinsert);
echo< table border ='1'>;
echo< tr>
< th> ID< th>
学校代码< th>
th类别< / th>
学校名称
学校地址
学校名称
< / tr>;
while($ row = mysqli_fetch_assoc($ result)){
$ id = $ row ['ID'];
echo< tr>
< td>;
echo $ row ['ID'];
回显< td>;
echo $ row ['category'];
回显< td>;
echo $ row ['sname'];
回显< td>;
echo $ row ['sadd'];
回显< td>;
echo $ row ['filename'];
echo< td>;
?>
< form name =formmethod =POSTaction =parentssubmit.php>
< input type =hiddenvalue =<?php echo $ id;?> NAME = 搜索 >
< input type =submitvalue =Viewname =View>
< / form>
<?php}
echo< / td>< / tr>;
echo< / table>;
============================================== ==========================
if(isset($ _ POST ['View'])){
$ pdf = new fpdf();
$ pdf-> ADDPage();
$ pdf-> setfont('Arial','B',16);
$ pdf->单元格(40,10,'sname',1,0,'c');
$ pdf->单元格(40,10,'sadd',1,0,'c');
$ pdf->单元格(40,10,'category',1,0,'c');
$ pdf->单元格(40,10,'scode',1,0,'c');
$ con = mysqli_connect(localhost,root,,school);
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}
$ file_filename = $ _ FILES ['file'] ['name'];
$ target_path =Newfolder1;
$ image_path = $ target_path。 DIRECTORY_SEPARATOR。 文件名;
$ 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);
}
//从数据库记录中构建数据数组。
虽然($ row = mysqli_fetch_array($ result)){
$ pdf->单元格(40,10,$ row ['sname'],1,0,'c');
$ pdf->单元格(40,10,$ row ['sadd'],1,0,'c');
$ pdf->单元格(40,10,$ row ['category'],1,0,'c');
$ pdf->图片($ image_path,50,100,50,20,$ image_format);
$ pdf-> ln();}
}
$ pdf-> output();
这是两页,出现错误未定义索引:
文件未定义的索引:文件,所以请尝试指出错误,因为当我添加图像字段时出现主错误,然后错误开始弹出。
首先,你应该关闭所有的
< tr>
和< td> $ h2_lin>解决方案
标签。其次,你没有发送任何文件到你的表单,因此你得到这个 Undefined index:file
错误,所以删除这些行,
$ file_filename = $ _ FILES ['file'] ['name'];
$ target_path =Newfolder1;
$ image_path = $ target_path。 DIRECTORY_SEPARATOR。 文件名;
$ image_format = strtolower(pathinfo('filename',PATHINFO_EXTENSION));
因此,在用户点击查看
按钮后,您应该像这样处理你的表单和显示图像,
//你的代码
if(isset( $ _POST ['View'])){
$ pdf = new fpdf();
$ pdf-> ADDPage();
$ pdf-> setfont('Arial','B',16);
$ pdf->单元格(40,10,'sname',1,0,'c');
$ pdf->单元格(40,10,'sadd',1,0,'c');
$ pdf->单元格(40,10,'category',1,0,'c');
$ pdf->单元格(40,10,'scode',1,0,'c');
$ con = mysqli_connect(localhost,root,,school);
if(mysqli_connect_errno()){
echo无法连接到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。 $行[文件名]; // path应该是这样的,process / upload / 8 / cdv_photo_001.jpg
$ image_format = strtolower(pathinfo($ image_path,PATHINFO_EXTENSION));
$ pdf->单元格(40,10,$ row ['sname'],1,0,'c');
$ pdf->单元格(40,10,$ row ['sadd'],1,0,'c');
$ pdf->单元格(40,10,$ row ['category'],1,0,'c');
$ pdf->图片($ image_path,50,100,50,20,$ image_format);
$ pdf-> ln();
$ pdf-> output();
}
//您的代码
$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();
this is two pages and error is coming out Undefined index:
file Undefined index: file so please try to point out the mistake because main error is showing when i added the image field then the error is started popping out.
- I am trying to fetch the image from the database and trying to show it in PDF format.
解决方案
First, you should close all your <tr>
and <td>
tags. Second, you're not sending any file with your form, and hence you're getting this Undefined index: file
error, so remove these lines,
$file_filename=$_FILES['file']['name'];
$target_path = "Newfolder1";
$image_path = $target_path . DIRECTORY_SEPARATOR . "filename";
$image_format = strtolower(pathinfo('filename', PATHINFO_EXTENSION));
So after user hits view
button, you should process your form and display image like this,
// 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
这篇关于fpdf错误和查看表错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文