0

I am trying to use isset($_POST['Save']) in my php file to save result in database.

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

saveResult.php:

<?php
if(isset($_POST['Save'])) // If the submit button was clicked
{
$serverName = "Alaa";
echo"saveResult function php";
$connectionInfo = array( "Database"=>"i2b2blast", "UID"=>"i2b2blast", "PWD"=>"demouser");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

$sql = "INSERT INTO BlastQueryDim (QueryID, QuerySeq) VALUES ('9', 'q')";

$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
     die( print_r( sqlsrv_errors(), true));
}
}
?>

but, I got this error:

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. The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request. A request was sent to the server that contained an invalid HTTP verb. The request is for static content and contains an HTTP verb other than GET or HEAD. A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.

Any help please?

Alaa
  • 175
  • 2
  • 14
  • what code you have in saveResult.php ? your current code is ok I think. – Niklesh Raut Mar 12 '16 at 09:11
  • This may indicate that your application stack at some point is not allowing POST requests to reach that particular site. – apokryfos Mar 12 '16 at 09:11
  • Possible duplicate of [What causes an HTTP 405 "invalid method (HTTP verb)" error when POSTing a form to PHP on IIS?](http://stackoverflow.com/questions/1400210/what-causes-an-http-405-invalid-method-http-verb-error-when-posting-a-form-t) – Always Sunny Mar 12 '16 at 09:15
  • may be that's because, you are not submitting anything using your form – Panda Mar 12 '16 at 09:19
  • @apokryfos So? what is the solution? – Alaa Mar 12 '16 at 09:30
  • Have you tried to remote the `action=''` from your `form` element and see if it's working? so the first line of your code will be like this: `echo "
    ";`,
    – EhsanT Mar 13 '16 at 03:12
  • @EhsanT either when i type action=' ' or remove action, i got this error and when i type action='file.php', it redirect the page and i do not want that. – Alaa Mar 13 '16 at 08:10
  • 1
    have you tried this for the action: `action=''`. But whatever the problem is, it's related to IIS(as I assume your web server is IIS and not apache or nginx or etc...) and it's config and it's not related to php, so if you could not solve your problem here, I suggest to post you question under the IIS tag. maybe in that community they have some information on this matter that can help you. – EhsanT Mar 13 '16 at 19:35

1 Answers1

0

There is a syntax error.
Try this:

    include 'filename';
davejal
  • 5,431
  • 10
  • 33
  • 73
Panda
  • 2,184
  • 2
  • 18
  • 33
  • I try it. The same error. The error occurs once I click the save button – Alaa Mar 12 '16 at 09:29
  • @Alaa try changing the method from post to get – Panda Mar 12 '16 at 09:30
  • @Alaa Is that file, in your same directory? If yes, try `include('./saveResult.php');` – Panda Mar 12 '16 at 09:37
  • I believe the cause of error is not the include statement. It is the POST statement. See edited question please and read the error displayed. – Alaa Mar 12 '16 at 09:43
  • Then, you need to use `GET` method over here. But that dosent make any sence – Panda Mar 12 '16 at 09:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/106082/discussion-between-m-s-p-and-alaa). – Panda Mar 12 '16 at 09:52