I am trying to make a page with form that allows people to submit requests to become a volunteer for the non-profit organization I am making a website for. These requests should be then logged into a database called "volunteers" on phpmyadmin. As for servers I am trying to work with Xampp with Apache and MySQL. When testing my page however, I simply get the error: Cannot Post /Connection.php. At some point of time in my trouble shooting, it simply displayed a page of the php code instead of the cannot post message while still not sending the data to phpmyadmin, however now it's back to the old cannot post stuff.
For reference, my two files here, the html file, "Register Volunteer.html" and the php file, "Connection.php" are within the same folder, which is within htdocs of Xampp where it is supposed to be. The server is active too and ran on administer permissions. The php file is heavily based on a college homework assignment I did a year ago. I feel like I've been bashing my head against a wall with for too long. Is there any flaws in my code that spring to mind to any experts out there? Do I perhaps need another file?
Here is "Register Volunteer.html"...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Soaring Dreams - Home</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div id="bannerimage"></div>
<header class = "aligncenter"></header>
<hr>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="About%20Us.html">About Us</a></li>
<li><a href="Gallery.html">Gallery</a></li>
<li><a href="Our%20Volunteers.html">Our Volunteers</a></li>
<li><a href="Custom%20Goods.html">Custom Goods</a></li>
</ul>
</nav>
<h2><i>Volunteer Registration</i></h2>
<form action="/Connection.php" method="post">
<fieldset>
<label> First name </label>
<input type="text" id="firstName" name="firstName" placeholder= "Firstname" size="20" required />
<br>
<label> Last name </label>
<input type="text" id="lastName" name="lastName" placeholder= "Lastname" size="20" required />
<br>
<label> Date of Birth </label>
<input type="date" id="age" name="age" required />
<br>
<label> Phone Number </label>
<input type="text" id="phoneNumber" name="phoneNumber" placeholder= "+1(123)123-1234" size="20" required />
<br>
<label> Email </label>
<input type="text" id="email" name="email" placeholder= "Something@blah.com" size="30" required />
<br>
<br>
<label>Why do you want to volunteer?</label>
<textarea rows="6" cols="100" id="reason" name="reason" placeholder= "Add your reason" size="600" required></textarea>
<br>
<br>
< type="submit" class="registerbtn">Register</>
</fieldset>
</form>
</body>
</html>
And here is "Connection.php"...
<?php
$servername = "localhost";
$username = "root";
$password = "examplePW";
$dbname = "volunteers";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully. <br>";
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$age = $_POST['age'];
$phoneNumber = $_POST['phoneNumber'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$sql = "INSERT INTO volunteerrequest(firstName, lastName, age, phoneNUmber, email, reason) VALUES" . "('$firstName', '$lastName', '$age', '$phoneNumber', '$email', '$reason')";
echo "Running SQL statement - <br>" . $sql . "<br>";
if($conn->query($sql) == TRUE)
{
echo "Request Sent <br>";
}
else{
echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
Again, any sort of help or guidance would be immensely appreciated.