We currently have 2 php pages. Page 1 - Form (submits to page 2) page 2 - Mysql query, submits to DB We want to add something in between where when the user gets to page #2, it doesn't automatically execute the query until the user clicks "continue". So the question is, how can I make the mysql query on page #2 not execute on page-load, but instead only when the user clicks a link on that page. I'm guessing I need ajax for this?
well.. at page 1, you can have a form (= form1) that redirects to page 2. at page 2, you have another form (= form2), which redirects to the same page (page 2). if the form1 redirected you, you'd show the second button. when you press the second button, it'll execute the mysql query. understand? EDIT: Just now seen you want to do it with AJAX. if so, make a third page with the query it self, and using ajax, call this page usin onclick function. pm me if you need help wit that
As for ajax, it depends if you want the page to reload, or the query to happen behind the scenes when the user clicks the button. If you're fine with the page reloading, you could just use a form to send them to any other script (or the same one, and just insert). i.e. pseudocode: if ( clickedSubmit() ) { // Insert query } else { // Output form w/ button } Code (markup): Otherwise your option would be to use Ajax. I'd personally recommend using a library like jQuery. Then you could do something like: <input type="submit" value="Submit" id="submitBtn" /> Code (markup): (function($) { $(document).ready(function() { $("#submitBtn").click(function() { $.ajax({ url: 'query.php', success: function() { $("#success").fadeIn(); } }); }); }(jQuery)); Code (markup): Untested, but you should get the general idea.