0

How can I run php file from another php file with onclick button?

My first.php file:

echo "<form action='saveResult.php' method='post' name='Post'>";
echo "<input name='Save' type='submit' value='Save Result'> </p>";

I want to run 'saveResult.php' from my first.php without redirect to 'saveResult.php' page.

Thanks,

Edit 1: I try:

echo "<form action='' method='POST' name='Post'>";
echo "<input name='Save' type='submit' value='Save Result'>";   
echo "</form>";
if(isset($_POST['Save'])){
require_once('saveResult.php'); // display error
include_once('saveResult.php'); // display error
include('saveResult.php'); // display error
}

The error is: HTTP Error 405.0 - Method Not Allowed The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

3
  • 1
    Possible duplicate of onclick replace php included file Commented Mar 11, 2016 at 11:53
  • first, show your complete code, how will it work property if you dont even close the <form>-tag. And second, action= always redirect, even if its pointed to itself. If you dont want it, use jacascript with onclick-function on your button and ajax-call. Commented Mar 11, 2016 at 13:43
  • @yangsunny How can I use js inside php file! Commented Mar 11, 2016 at 14:43

4 Answers 4

1

First remove action from your form tag

echo "<form method='post' name='Post'>";

Try this

if(isset($_POST['Save']))
{ 
   include('secondpage.php');
}
Sign up to request clarification or add additional context in comments.

3 Comments

if(isset($_POST['Save'])) always display an error. I write form action=''
HTTP Error 405.0 - Method Not Allowed The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
@Alaa have you removed the action?
0

Change method "post" to "POST"

Change your from action attribute to blank("") and then include that file in first.php with PHP functions like

if(isset($_POST['Save'])){
    include_once('saveResult.php');
}

OR

if(isset($_POST['Save'])){
    require_once('saveResult.php');
}

3 Comments

Your answer is partial true. OP has asked "with onclick button".
if(isset($_POST['Save'])) always display an error. I write form action=''
@Mihir Bhatt HTTP Error 405.0 - Method Not Allowed The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
0

please add the following code to your code

echo "<form action='' method='post' name='Post'>";
echo "<input name='Save' type='submit' value='Save Result'> </p>";
if(isset($_POST['Save'])){
    ob_start();
    include('saveResult.php');
    $output = ob_get_contents();
    ob_end_clean();
    echo '>>>>' . $output . '<<<<';   // here is the output from saveResult.php
}else{
    echo "No POST";
}

Hope this will help you.. Good luck..

Comments

0

Is your web server configured to handle PHP files for POST verbs?

EDIT

Try to configure this in IIS through going into Handler Mappings, and editing the PHP script map to handle the POST verb

EDIT

To add Handlers visit this link please. https://www.iis.net/configreference/system.webserver/handlers/add

Importent, check in tab 'verbs' that you have entered '*' or 'GET,HEAD,POST'

4 Comments

You should give comments directly to the question instead of asking as an answer.
What do you mean by that?
@Alaa Please check this link. Add a Module Handler Mapping | link
@Basti could you please give me the detailed step? what should I write in Module? and Excutable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.