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.
 
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.
 
Back
Top Bottom