如何在php中一键保存数据和打印表单?

如何在php中一键保存数据和打印表单?,php,pdf,printing,Php,Pdf,Printing,我正在处理发票,我必须将表格数据保存在数据库中,同时打印。因此,我有3个页面:invoice.php、invoice\u print.php和insert\u data.php invoice_print.php是一个应该打印的html表单 现在,用户将转到first invoice.php,然后填写详细信息,或者单击submit按钮将数据保存在db中,或者单击print按钮打印该发票 现在,让我们来看第二部分:如果用户选择“打印”按钮,那么数据将首先进入数据库,然后进入invoice_prin

我正在处理发票,我必须将表格数据保存在数据库中,同时打印。因此,我有3个页面:invoice.php、invoice\u print.php和insert\u data.php

invoice_print.php是一个应该打印的html表单

现在,用户将转到first invoice.php,然后填写详细信息,或者单击submit按钮将数据保存在db中,或者单击print按钮打印该发票

现在,让我们来看第二部分:如果用户选择“打印”按钮,那么数据将首先进入数据库,然后进入invoice_print.php,其中包含他填写的相同数据

如何做到这一点?我应该使用什么逻辑来保存数据并在按钮中捕获该数据的id,然后将该id发送到另一个页面上显示

invoice.php:

<form id="demo-form2"  action="insert_data.php" method="post" data-parsley-validate class="form-horizontal form-label-left">
<div class="col-md-12 form-group">
  <div class="col-md-6">
    <label class="control-label">Location</label>
  </div>
  <div class="col-md-6">                                  
    <input class="form-control" type="text" value="" name="designation">  
  </div>                         
</div>        
<div class="col-md-12 form-group">
  <div class="col-md-6">
    <label class="control-label">Address</label>
  </div>
  <div class="col-md-6">                                  
    <input class="form-control" type="text" value="" name="contact">  
  </div>                         
</div>
</form>

位置
地址
invoice_print.php:

<div class="col-md-12">
  <div class="col-md-6">
    <h2>DIGILIFE BIZCARE SOLUTIONS</h2>
    <p>414, Vashi Infotech Park,Maharashtra</p>
  </div>
  <div class="col-md-6">
    <h2>BILL OF SUPPLY</h2>
  </div>
</div>
<div class="col-md-12">
  <div class="col-md-6">
    <div class="col-md-12">
      <div class="col-md-6">
        <label>GSTIN</label>
        <input type="text" name="gstin" value="">
        <label>Serial No & Date of Invoice</label>
        <input type="text" name="serialNo">
      </div>
      <div class="col-md-6">

      </div>        
    </div>  
  </div>
  <div class="col-md-6">
    <div class="col-md-12">
      <div class="col-md-6">
        <label>Mode of Transport</label><br>
        <label>Vehicle No</label><br>
        <label>Date & Time of Supply</label><br>
        <label>Place Of Supply</label>
      </div>
      <div class="col-md-6s">
        <input type="text" name="">
        <input type="text" name="">
        <input type="text" name="">
        <input type="text" name="">
      </div>
    </div>
  </div>
</div>
<div class="col-md-12 form-group">
  <div class="col-md-6">
    <label class="control-label">Location</label>
  </div>
  <div class="col-md-6">                                  
    <input class="form-control" type="text" value="" name="designation">  
  </div>                         
</div>        
<div class="col-md-12 form-group">
  <div class="col-md-6">
    <label class="control-label">Address</label>
  </div>
  <div class="col-md-6">                                  
    <input class="form-control" type="text" value="" name="contact">  
  </div>                         
</div>

DIGILIFE BIZCARE解决方案
马哈拉施特拉邦瓦希信息技术园414号

供货清单 GSTIN 发票序列号和日期 运输方式
车辆编号
供应日期和时间
供应地 位置 地址
我会将表单的所有代码放在一个文件中,结构如下:

<?php
$formDone=!empty($_POST['formDone']);
$printReq=!empty($_POST['printReq']);
if ($formDone)
{
    // perform validation
}
if ($formDone && $validationPassed)
{
    // write to database using $_POST data
}
if ($formDone && $databaseWriteSuccess && $printReq)
{
    // print using $_POST data
}
// end of PHP
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<fieldset>
    <input type="hidden" name="formDone" value="1" />
</fieldset>
    <!-- field forms -->
<input type="submit" value="Save to db" />
<input type="submit" name="printReq" value="Print Invoice" />
</form>


您不需要将invoice_print.php和insert_data.php分开。将这两个文件放在一个文件中,例如,我们称这个新文件为combine.php。如果用户单击提交按钮转到combine.php并保存,如果用户单击打印转到combine.php并保存,则显示发布的信息。很高兴提供帮助:)