hmdnawaz Posted January 6, 2011 Share Posted January 6, 2011 I have two pages one is db.php and another is form.php. In form.php i have created a form which contains different fields and a submit button. But i want to write the queries in db.php. And when i click on the submit button the insert query in db.php should be executed and insert data in database but the focus remains on form.php. How can i do this??? Any Idea? Quote Link to comment https://forums.phpfreaks.com/topic/223547-how-can-i-call-a-function-of-another-page-on-submit-button-of-a-form/ Share on other sites More sharing options...
denno020 Posted January 6, 2011 Share Posted January 6, 2011 <form action="db.php"> Obviously there will be more things inside the form tag, but I couldn't be bothered writing them, the action is all you need to make the form send to another php script . Denno Quote Link to comment https://forums.phpfreaks.com/topic/223547-how-can-i-call-a-function-of-another-page-on-submit-button-of-a-form/#findComment-1155566 Share on other sites More sharing options...
hmdnawaz Posted January 6, 2011 Author Share Posted January 6, 2011 but db.php have a class and a function. How can i call that function from the submit button of form.php? Quote Link to comment https://forums.phpfreaks.com/topic/223547-how-can-i-call-a-function-of-another-page-on-submit-button-of-a-form/#findComment-1155571 Share on other sites More sharing options...
denno020 Posted January 6, 2011 Share Posted January 6, 2011 you can have an if statement at the top of the page, so see if anything has been posted. And then include the db.php file in that. Else, nothing. You give the form no action, so that the same page is loaded, and the if condition is run. This way you can leave all of your query information in the db.php file, and you keep focus on the form.php page, as you originally asked. reference: http://stackoverflow.com/questions/595358/how-can-i-execute-a-php-function-in-a-form-action I found the above link doing a very simple google search.... Denno Quote Link to comment https://forums.phpfreaks.com/topic/223547-how-can-i-call-a-function-of-another-page-on-submit-button-of-a-form/#findComment-1155575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.