I have a form in which there are two fields: amount input and submit button. On submitting this form I want the data to be stored in database and should be displayed in pdf using tcpdf. Everytime i add an amount it should be appended to a table in a row inside pdf. How to do this?? Please help me with this.
Following is the form which submits the amount:
<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>
Following is the php code using tcpdf:
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');}
Here when i submit the form, i want the date of payment and amount should be displayed in the table row of pdf and each time i do this the row should be appended to the pdf. pdf is printed using pdf button which is in other code which i have not mentioned here.