How to perform Multiple operation like print form and store into database at the same time using single button?

how to perform print button to print form and add button to add into database operation using single button using php and html?
Nikhil DangeWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It is going to be both PHP and html
You'd likely use Javascript / AJAX to do this, since HTML and PHP cannot invoke the print process. You didn't provide a ton of detail here, so the high-level overview would be this:

<input type='button' value='Save and Print' onclick='saveAndPrint();'>

Open in new window

Then you'd have a Javascript function called saveAndPrint() that would use AJAX to save your data and call the window.print method. I'll use jQuery syntax (

<script type="text/javascript">
function saveAndPrint()
  $.post( "/path/to/DatabaseSaveScript.php", { name: "John", time: "2pm" }).done(function( data ) {
    alert( "Data Loaded: " + data );


Open in new window

This code is very generic - you'd have to customize it to pass the right data to the right script, for example.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What information do you want to store in the db?
Your form has an action, the action calls the php.  Then in the php when the button is clicked (TRUE) then run a query to insert into the DB.  Give me a little more info or a URL and I / We can help you out a little more.

And Anything that gr8gonzo suggests.
SolarWinds® VoIP and Network Quality Manager(VNQM)

WAN and VoIP monitoring tools that can help with troubleshooting via an intuitive web interface. Review quality of service data, including jitter, latency, packet loss, and MOS. Troubleshoot call performance and correlate call issues with WAN performance for Cisco and Avaya calls

mohan singhWeb developerCommented:
Use to data-table working concept to full fill your requirements
in data-table you can do live update import, export, copy, excel etc
Nikhil DangeWeb DeveloperAuthor Commented:
I want to perform 2 action simultaneously over 'Save and Print' button on form using JavaScript, HTML

mohan singhWeb developerCommented:
Are using php for save your data in database ?
Nikhil DangeWeb DeveloperAuthor Commented:
mohan singhWeb developerCommented:


$sql = mysql_query($conn, " INSERT INTO table ('democolumn') values('demoData');";
// after insert data
//fetch that max id which you inserted in database then

$sql2= mysql_query();//fetch max id and pass it into next page 

echo "<script>window.location = 'print.php?id=$id'</script>";

// after that get it in your print page and again fetch data and echo all data which you want to print 


Open in new window

Nikhil, I already answered this - if you don't understand or need more information, please provide feedback.
mohan singhWeb developerCommented:
mr. gr8gonzo give best answer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.