skip to Main Content

so I’m new to php and I’m working on a school task. Its a simple form that will take the inputs and write it to a txt file. But for me it doesn’t work. I tried to make a test version to see where the problem is and the error i get is 405 method not allowed. I have used fopen and fwrite too but they dont work too.

enter image description here

Here is my html code

<!DOCTYPE html>
<html lang="No">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index1</title>
</head>
<body>
 
  <form method="post" action="test21.php" name="myForm">
    klassekode <input type="text" id="klassekode" name="klassekode" required />
    <input type="submit" value="Fortsett" id="fortsett" name="fortsett" />
  </form>
 <a href="klasse.txt">Vis  klasser </a> 
               
</body> 
</html>


and my very simplified php code that i used to test test21.php

<?php
file_put_contents("klasse.txt", "test");
?>

2

Answers


  1. "405 method not allowed" means you aren’t allowed to make a POST request to that URL.

    Your screenshot shows that you are making the request to a server running on port 5500.

    This is the default port for VS Code Live Server so I’m going to assume you are using that.

    VS Code Live Server does not support PHP, or any form of server side programming, and will give 405 errors for POST requests.

    You need to switch to an HTTP server that supports PHP. The introduction page in the PHP manual has some pointers.

    Login or Signup to reply.
  2. You should have a mis configuration of the web server. It reply 405 so it means that http method POST is not allowed by the server. You can see that POST is not in the Allow: header too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search