1

Hi I am a beginner to programming and have just started learning PHP and wanted to run some experiments with it on my own on visual studio code but when I run the program on live server, it gives me an error can anybody help me?

 <html>
<head>
</head>
<body>
    <form action="thing.php" method="POST">
        <label for="firstname">First Name:</label>
        <input type="text" id="firstname" name="firstname" /><br />
        <input type="submit" value="Report Abduction" name="submit">
    </form>
</body>
</html>

and in thing.php i wrote

<html>
<head>
</head>
<body>
<h2>Testing</h2>
    <?php
    $first_name=$_POST['firstname'];
    echo 'Your first name is '. $first_name;
    ?>
</body>
</html>

The error i received is This page isn’t working If the problem continues, contact the site owner. HTTP ERROR 405

7
  • 2
    “An error” is not a useful description of the problem. Try quoting the actual error message. Commented Sep 6, 2020 at 23:38
  • Yes, sorry I am new to stack overflow, i edited my question to quote the error Commented Sep 6, 2020 at 23:49
  • What is "live server"? Is that some VS Code extension? Commented Sep 7, 2020 at 0:24
  • In order to run PHP code, you need a server capable of doing so. PHP comes with one pre-installed so provided you actually installed PHP, from your VSCode terminal, try running php -S localhost:8000 then open your browser to http://localhost:8000/ Commented Sep 7, 2020 at 0:29
  • Yes live server is a VS code extension Commented Sep 7, 2020 at 0:29

1 Answer 1

2

HTTP 405 means “Method not allowed”. In this case, it is the POST request that is not allowed.

The VS Code Live Server extension (not to be confused with the browser extension that Phil linked to in the comments) only supports static files. It doesn’t support PHP.

Since it doesn’t support any kind of server-side programming, it doesn’t make sense to make a POST request do it, so it throws an error when you do.

You need to use a web server which supports PHP instead.

PHP has a built-in development server which is quick to get up and running. You might also consider using the same server that your production environment would use to minimise differences between your development environment and other environments your code will run in.

Sign up to request clarification or add additional context in comments.

1 Comment

I only linked it because it mentions both the browser add-on and the extension. "Neither the browser add-on nor the VS Code extension will host a server for: PHP, .NET or NodeJS"

Your Answer

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