How to run PHP with vscode

点点圈 提交于 2021-02-11 17:00:43

问题


I'm trying to create a simple HTML form that redirects users to a thank you message displayed by the server, and written in PHP. However, nothing I do seems to work. I get a 405 every time I try to run the code. If I refresh the page it starts downloading. I'm using the live server extension and I have PHP installed.

HTML file:

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel = "stylesheet" type = "text/css" href = "styles-signup.css">
    <script type = "text/javascript" src = "script-signup.js"></script>

</head>
<body>
    <div>
        <h1 class = "title"></h1>
    </div>
    <div class = "form">
        <h1 id = "header">Create Your Account</h1>
        <form method = "POST" id = "signup" action = "action.php">
            <input name = "firstName" type = "text" placeholder="First Name" required id = "fname">
            <input name = "lastName" type = "text" placeholder = "Last Name" required id = "lname">
            <input name = "Email" type = "email" placeholder="email, e.g. person@gmail.com" required id = "mail">
            <input name = "newPassword" type = "password" id = "password" placeholder="Password" required minlength="8" maxlength="25">
            <input name = "passwordConfirm" type = "password" placeholder = "Confirm Password" required minlength="8" maxlength="25" id = "cpassword">
           <br>

           <input name = "gender" type = "radio" id = "male" required>
           <label for = "gender" id = "mlabel">Male</label>

           <input name = "gender" type = "radio" id = "female" required>
           <label for = "gender" id = "flabel">Female</label>

           <input name = "gender" type = "radio" id = "other" required>
           <label for = "gender" id = "olabel">Other</label>
           <br>

           <br>
           <input name = "birthdate" type = "number" min = "1920" max = "2019" placeholder="Year Of Birth" id = bd required>
           <br>

            <input name = "terms" type ="checkbox" id = "box" required>

            <p id = "tc">I agree to the <a href = "termsandconditions.txt" id = "tcLink">Terms and Conditions</a></p>

            <input name = "submit" type = "Submit" id = "button" value = "Sign up">

            <a href = "login.html" id = "login">Already have an account? Log in</a>

        </form>
    </div>

</body>
</html>

PHP File:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <?php
    echo "<p>Hi</p>";
    ?>

</body>
</html>

I get this error:


回答1:


You need to set-up a server to be able to use PHP. If you use windows their are a couple easy to use options, try downloading one of these:

  1. XAMPP
  2. WAMP

If you are on Linux you will need to build a LAMP server. If you are on mac, I think it is called OS-X. It sounds like your new to all this. I highly suggest setting up a server, it will really help you understand how websites work, and also give you the ability to write and learn server-side languages like PHP and ASP.

Just as a note, servers interrupt PHP, not editors and IDE's.



来源:https://stackoverflow.com/questions/59537824/how-to-run-php-with-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!