我有一个表单,其中有两个字段:金额输入和提交按钮。在提交此表单时,我希望将数据存储在数据库中,并使用tcpdf以pdf格式显示。每次我添加一个金额时,它应该附加到pdf内的一行表中。这该怎么做??请帮帮我。
以下是提交金额的表格:
<div class="form-group">
<label class="col-sm-3 control-label" for="amount">Amount</label>
<div class="col-sm-9">
<input type="number" class="form-control" name="amount"
id="amount" placeholder="Amount">
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<button type="submit" class="btn btn-success" id="pay-now" name="pay-
now">Pay Now</button>
</div>
</div>
以下是使用tcpdf的PHP代码:
if(isset($_POST["pdf"]))
{
require_once('tcpdf/tcpdf.php');
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8',
false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '',
PDF_FONT_SIZE_MAIN));
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '',
PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '4', PDF_MARGIN_RIGHT);
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false);
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('helvetica', '', 12);
$obj_pdf->AddPage();
$sql = "SELECT * FROM donors WHERE user_name='$username'";
$result = mysqli_query($conn, $sql);
$html = '';
$html .= '
<!doctype html>
<html lang="en">
<head>
<style>
.text-center{
text-align: center;
}
.img-fluid{
width: 200px;
height: 41px;
}
.title{
text-decoration: underline;
}
.text-left{
text-align: left;
}
</style>
</head>
<body>
<div >
<div class="text-center">
<div >
<img src="img/logo.png" class="img-fluid">
</div>
<div class="title">
<h1>Donation Report</h1>
</div>
<div >
<h3 >';
$html .= "Date : " . date("m-d-Y");
$html .= '</h3>
</div>
<div class="text-left">
<h4>Hello ';
$html .= $_SESSION['u_user_name'];
$html .= ',</h4>
<p>Thanks a lot for donating and supporting us. Please find your
details below for tax filing:</p>
</div>
<div>
<table border="1" cellspacing="0" cellpadding="5" id="box">
<tr>
<td>Date</td>
<td>Amount</td>
</tr><tr><td>';
$html .= date("m-d-Y");
$html .= '</td><td>';
while($row = mysqli_fetch_assoc($result)){
$html .= $row["total_donation_amount"];
}
$html .= '</td></tr></table>
</div>
<div class=" text-left">
<h4>Thanks and Regards,</h4>
<h4>Detroit Pheonix Center</h4>
<h4>Detroit, Mi</h4>
</div>
</div>
</div>
</body>
</html>';
$obj_pdf->writeHTML($html);
$obj_pdf->Output('donor_report.pdf', 'D');}
在这里,当我提交表格时,我希望付款日期和金额应显示在pdf的表格行中,每次我这样做时,该行应附加到pdf。 pdf是使用pdf按钮打印的,这是我在这里没有提到的其他代码。