PHP > mySQL update form help

Man of Honour
Joined
17 Feb 2003
Posts
29,640
Location
Chelmsford
Not quite my programming arena , but my son is having an issue with a form submission while trying to update a MYSQL database.

We keep getting the following error:

HTTP Error 405.0 - Method Not Allowed​

The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.​


Using a simple table called contactdata, with just an ID and first name.. for now.



index.html


HTML:
<html>

<head>

      </head>

<body>
    <div class="container">

  <form action="demo.php" method="post" >

<p>firstname: <input type="text" name="firstname" /></p>

 <input type="submit" value="submit" />

 </form>

    </div>

</body>



</html>


demo.php


PHP:
<?php

$servername = "localhost";
$username = "root";
$password = "Passwordtbc";
$db = "contactdata";

$con = new mysqli($servername, $username, $password, $db);

if ($con->connect_error) {

    die("Connection failed " . $con->connect_error);

} 

echo 'Connected Sucessfuly';

$Value = $_POST["firstname"];

$sql = "INSERT INTO contactdata (firstname) VALUES ('$Value')";


if ($con->query($sql) === TRUE) {
    echo "Records updated: ";
} else {
    echo "Error: " . $sql . "<br>" . $con->error;
}

$con->close();

?>



Web.config



Code:
<?xml version="1.0"?>

<configuration>

  <!--

    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.

      <system.Web>

        <httpRuntime targetFramework="4.5" />

      </system.Web>

  -->

  <system.web>

    <compilation debug="true" targetFramework="4.5"/>

    <pages controlRenderingCompatibilityVersion="4.0"/>

       

  </system.web>



</configuration>


Google's plenty of possible solutions, but none have managed to resolve this.


Any idea would be greatly appreciated.
 
Soldato
Joined
24 Jun 2021
Posts
3,633
Location
UK
You need to instruct the web server how to handle the POST http verb, i.e. pass it to PHP. In IIS it's called "handler mapping". I'm not having much luck with google either tbh, hosting php in iis is an odd choice, people use apache/nginx instead.

p.s. be sure to learn about "sql injection" before putting this website live.
 
Man of Honour
OP
Joined
17 Feb 2003
Posts
29,640
Location
Chelmsford
Where is it being hosted?
It's a local installation - just as an exercise.

You need to instruct the web server how to handle the POST http verb, i.e. pass it to PHP. In IIS it's called "handler mapping". I'm not having much luck with google either tbh, hosting php in iis is an odd choice, people use apache/nginx instead.

p.s. be sure to learn about "sql injection" before putting this website live.

Ok, thanks.. I have been looking at that, setting post to Allowed but not much joy.
 
Soldato
Joined
3 Jun 2005
Posts
3,070
Location
The South
It's been a while using IIS but as @throwaway4372 says, it's to do with your 'Handler Mappings' and PHP. I would make sure you have configured PHP properly under IIS, this guide may help.

I would also look at using something like WAMP or MAMP instead to provide a WAMP (Windows Apache MySQL PHP) stack instead, rather than using IIS.
And don't use MySQLi, use PHP PDO instead for the DB connections along with PDO bindings as it'll help with SQL injections.
 
Caporegime
Joined
19 May 2004
Posts
31,566
Location
Nordfriesland, Germany
It's a local installation - just as an exercise.

What are you using?

I recommend ddev (which I use now), or failing that, xampp (which I used before I came across ddev). Both will set up an Apache server with MySQL and PHP suitable for local dev in a couple of steps. XAMPP is a little easier, DDEV is better (imo) but you'll want to set up WSL2 first which makes it a little more complicated.
 
Last edited:
Back
Top Bottom