i am trying to create a application that submit html form data to my database using .php.
When I think through what my code is doing logically I am doing the following:
- user enters corresponding form data
- user hits enter
- once user hits enter, the form calls my .php file and is suppose to get form data and parse it so that mysql query can insert that data into my database. During this step is when I get the 405 HTTP Error.
I do not currently have my site live using a DNS, so I am utilizing XAMPP. Since getting the 405 HTTP error I have googled the error and this is what I seen "The 405 Method Not Allowed error occurs when the web server is configured in a way that does not allow you to perform a specific action for a particular URL. It's an HTTP response status code that indicates that the request method is known by the server but is not supported by the target resource."
I am using 127.0.0.1:5500 as the server.
After googling, I figured since I was using live server it wasnt able to parse out the .php file which then threw the error. So next, I tried to load the site on my php server with the php server extension on visual studio code. When I use the php server my "server" switches to localhost:30000/services.html instead of 127.0.0.1/services.html. when using the php server it take it an extremely long time to load so I am unsure if this is actually working.
This is my html code:
<form action="DBWriteTo.php" name="clientInterest" method="post">
<h1>First & Last Name:</h1>
<input type="text" name="firstName" placeholder="Please Enter First Name"/>
<input type="text" name="lastName" placeholder="Please Enter Last Name"/>
<h2>Company Name:</h2>
<input type="text" name="companyName" placeholder="Enter Company Namee"/>
<input type="text" name="phone" placeholder="enter phone number"/>
<h3>What type of Service:</h3>
<input type="radio" id="basic" name="typeOfService"/><br>
<label for="basic">Basic</label>
<input type="radio" id="deluxe" name="typeOfService"/><br>
<label for="radio">Deluxe</label>
<input type="radio" id="premuim" name="typeOfService"/><br>
<label for="premuim">Premuim</label>
<h4>e-mail:</h4>
<input type="text" name="email" placeholder="Enter email" />
<input type="submit" name="clientInterest" value="Contact Us"/>
</form>
This is my .php file code:
<?php
$firstName = $_REQUEST['firstName'];
$lastName = $_REQUEST['lastName'];
$companyName = $_REQUEST['companyName'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$con = mysqli_connect('127.0.0.1:5500',username,password,DB);
//create DB connection
//CHECK CONNECTITON
IF($con->connect_error){
die('Connection Failed'. $con->connect_error);
}
echo 'CONNECTED!';
$sql = "INSERT INTO pclient VALUES ('$firstName','$lastName','$email','$companyName')";
if(mysqli_query($conn, $sql)){
echo "data stored in a database successfully navigate to your database to view the updated data";
}else{
echo "error saving data Sorry $sql"
. mysqli_error($conn);
}
mysqli_close($conn);
?>
I also looked at how the server was set up in the config file
This is what the 405 error that I get
Has anyone else have this problem, if so what did you do to correct?

