简体   繁体   中英

How to use php on visual studio code

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM