在PHP中提交按钮后打印帐单发票

I have two columns item name and amount. I just click the submit button and then I want to print the invoice. I already set the invoice format and I know onclick="window.print() but in this case the page prints everything. I only want to print the invoice format after the submit button.

<form method="post">
item name
<input type="text" name="item">
amount
<input type="text" name="amt">
<input type="submit" name="submit">

</form>
<?php
if(isset($_POST['submit'])){

    $item = $_POST['item']  ;
    $amt = $_POST['amt']  ;


    // want print I have set the invoice

    }

?>

You should use JavaScript instead of php. Please put the printing part inside a div with an id As:

<div id="print_setion">
      <h1>Print This Setion Only</h1>
</div>

<input type="button" onclick="printDivSection('print_setion')" value="Print This Setion Only" />

and create JavaScript as :

function printDivSection(setion_id) {
     var Contents_Section = document.getElementById(setion_id).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = Contents_Section;

     window.print();

     document.body.innerHTML = originalContents;
}

Note: innerHTML get only div section that is inside id <div id="print_setion">