如何删除FPDF中的此错误


How to remove this error in FPDF?

我使用FPDF以pdf格式显示以html形式提交的数据。我已经研究了之前问题的所有解决方案,但我无法解决这个问题。我得到错误:

注意:未定义的变量:s_第9行C:''examplep''htdocs''dynamic-website''form1.php中的名称FPDF错误:一些数据已经输出,无法发送PDF文件

我的部分html代码是

<td align="right" valign="top">
  <label for="student3_name">3.Name </label>
  </td>
<td valign="top">
  <input  type="text" name="student3_name" maxlength="50" size="20" >
  </td>

我的form1.php如下:

<?php
   if(isset($_POST['submit']))
   {$s_name = $_POST["student3_name"];}
   require ("fpdf/fpdf.php");
   $pdf=new FPDF('P','mm','A4');
   $pdf->AddPage();
   $pdf->SetFont('Arial','B',16);
   $pdf->Cell(0,50,'',0,1);
   $pdf->Cell(60,10,"hello{$s_name}",10,8,'C');
   $pdf->output();
?>

编辑:这是我的表格的详细部分

<form name="submission_form" method="post" action="form1.php">
  <p style="text-align: center; font-size: 24px; font-weight: 900;></p>
  <table width="634" align="center" border="1">
  <tr>
  <td align="right" valign="top">
  <label for="student3_name">3.Name </label>
  </td>
  <td valign="top">
  <input  type="text" name="student3_name" maxlength="50" size="20" >
  </td>
  </tr> 
  <tr>
  <td colspan="4" style="text-align:center">
  <input type="submit" value="Submit"></td>
  </tr>

将代码更改为:

<?php
       $s_name = "";
       if(isset($_POST['submission_form']))
       {
               $s_name = $_POST["student3_name"];
       }
       require ("fpdf/fpdf.php");
       $pdf=new FPDF('P','mm','A4');
       $pdf->AddPage();
       $pdf->SetFont('Arial','B',16);
       $pdf->Cell(0,50,'',0,1);
       $pdf->Cell(60,10,"hello{$s_name}",10,8,'C');
       $pdf->output();
    ?>

将您的提交按钮更改为此

<input name="submission_form" type="submit" value="Submit">

您在块内声明$s_name变量,该变量在块外是不可见的,因此除了在声明它的块内,您不能在其他任何地方使用它。

isset($_POST['submit'])返回false的情况下,您需要一个else条件来定义s_name

类似于:

if (isset($_POST['submit'])) {
    $s_name = $_POST['student3_name'];
} else {
    $s_name = 'The form hasn''t been submitted yet!';
}

跟上您的编辑:

还要确保提交按钮正在公布其值。为了实现这一点,您需要包含一个名称属性:

<input name="submit" type="submit" value="Submit"/>