简体   繁体   English

如何清除FPDF中的此错误?

[英]How to remove this error in FPDF?

I'm using FPDF to show the data submitted in html form in pdf. 我正在使用FPDF以pdf格式显示以html形式提交的数据。 I've gone through all the solutions given on previous questions but I'm unable to solve this. 我已经解决了先前问题中给出的所有解决方案,但无法解决。 I'm getting the error: 我收到错误消息:

Notice: Undefined variable: s_ name in C:\\xampp\\htdocs\\dynamic website\\form1.php on line 9 FPDF error: Some data has already been output, can't send PDF file 注意:未定义的变量:第9行的C:\\ xampp \\ htdocs \\ dynamic website \\ form1.php中的s_名称FPDF错误:已经输出了某些数据,无法发送PDF文件

Part of my html code is 我的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>

and my form1.php is as follows: 我的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();
?>

EDIT: here is the detailed part my form 编辑:这是我的表格的详细部分

<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>

Change your code to this: 将代码更改为此:

<?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();
    ?>

Change your submit button to this 将您的提交按钮更改为此

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

You are declaring $s_name variable inside a block, that variable is invisible outside of the block so you cannot use it anywhere else except inside the block where it is declared. 您在一个块内声明$ s_name变量,该变量在该块外不可见,因此您不能在声明该块的其他地方使用它。

You need an else condition that will define s_name in the case that isset($_POST['submit']) returns false. isset($_POST['submit'])返回false的情况下,您需要一个else条件来定义s_name

Something like: 就像是:

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

Keeping up with your edits: 跟上您的编辑:

Also ensure that the submit button is posting its value. 还要确保“提交”按钮正在发布其值。 In order for this to occur you need to include a name attribute: 为了使这种情况发生,您需要包括一个名称属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM