Search code examples
phphtmlforms

HTTP Error 405 in a user registration form


I have to connect a user registration by post method in php for a subject and the teacher gave us the php code to do it but it doesn't work. Iḿ using Linux.

Here is the form, registro.html:

 <form action="registro.php" method="POST">
                <h1>Registro</h1>
                <label for="name">Nombre</label>
                <div><input type="text" name="nombre" id="nombre" placeholder="Nombre"></div>
                <label for="name">Apellido Paterno</label>
                <div><input type="text" name="name" id="" placeholder="Apellido Paterno"></div>
                <label for="name">Apellido Materno</label>
                <div><input type="text" name="name" id="" placeholder="Apellido Materno"></div>
                <label for="name">Edad</label>
                <div><input type="text" name="name" id="" placeholder="Edad"></div>
                <label for="name">Numero de telefono</label>
                <div><input type="text" name="name" id="" placeholder="Ej.33 1234 5678"></div>
                <label for="name">Codigo Postal</label>
                <div><input type="text" name="name" id="" placeholder="Ej. 12344"></div>
                <label for="name">Correo electronico</label>
                <div><input type="text" name="correo" id="" placeholder="Ej. [email protected]"</div>
                <label for="name">Contraseña</label>
                <div><input type="password" name="contrasena" id="" placeholder="*********"></div>
                <button>REGISTRAR</button>
            </form>

But I get Error 405 after submitting it.


Solution

  • For a simple HTML form, error 405 Method not allowed most likely means that you don't have PHP installed, so your server don't know how to handle POST requests.

    The simplest way to install PHP on Windows would be

    • go to https://windows.php.net/download
    • download .zip version from the current stable PHP section
    • unzip it into a certain folder on your PC (i.e. C:\PHP)
    • press Win-R, type cmd.exe and hit Enter
    • switch to the folder of your PHP project, (i.e enter cd "C:\Users\User\Documents\PHP" or whatever the folder is and hit Enter)
    • enter C:\PHP\php.exe -S localhost:8080 (using exact folder name where you unzipped PHP)
    • then go to your browser and type http://localhost:8080/script.php

    Or you can use one of prebuilt servers such as XAMPP and such.

    On Linux you can install PHP from the packet manager, such as sudo apt install php