0

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.

ADH - THE TECHIE GUY
  • 4,125
  • 3
  • 31
  • 54
Abhinay Raj
  • 27
  • 10
  • Code? where is the code you are working on .ad into your question by editing – Muhammad Omer Aslam Jun 10 '18 at 18:32
  • You dont append it to the file,instead you need to retrieve the old and new data from the db and rewrite the file (replace it with the new updated version with the same name) – USER249 Jun 10 '18 at 18:35
  • Hi, i have updated my code. Plz help me. – Abhinay Raj Jun 10 '18 at 18:48
  • @Amr Berag How should i do it?? Can u clearly explain?? . One more thing everytime the submit the form i overwrite the amount value in db. is there a alternate solution rather than overwriting. – Abhinay Raj Jun 10 '18 at 18:48
  • @AbhinayRaj well yes, you add it instead of overwriting. Perhaps you need a second table which references the first one – JensV Mar 20 '19 at 15:33

0 Answers0