$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();
这是两页,错误出现未定义索引:
文件未定义的索引:文件所以请尝试指出错误,因为当我添加图像字段时出现主要错误然后错误开始弹出。
答案 0 :(得分:2)
首先,您应该关闭所有<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