I have created a html form and want to connect it to a database on xampp. I have created the database and tables but the when I click submit, the php file does not work. I am new to web development. If I just run http://localhost/connect.php
then it works but when I click submit on the form, it redirects to file:///F:/Xampp/htdocs/connect.php
opens and shows the error. This is the html code for my form.
<form method="post" onSubmit="return validateForm();" action="connect.php">
<input type="text" id="fname" name="fname" class="input-box" maxlength="20" pattern="[A-Z]{1}[a-z]{2,}"placeholder="First Name" required autofocus>
<input type="text" id="lname" name="lname" class="input-box" maxlength="20" pattern="[A-Z]{1}[a-z]{2,}" placeholder="Last Name" required>
<br>
<br>
<input type="email" id="dataemail" name="dataemail" class="input-box" style="width: 48%;" placeholder="Your Email ID" required>
<br><br>
<input type="password" id="datapass" name="datapass" class="input-box" style="width: 48%;" placeholder="Password" required>
<br><br>
<input type="text" id="dob" name="dob" class="input-box" style="width: 48%;" placeholder="Date of Birth" onfocus="(this.type='date')" min="1901-01-01" max="1999-12-31" required>
<br>
<p style="font-size:150%;">
<input type="radio" id="male" name="gender" value="Male" required>
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label>
<input type="radio" id="other" name="gender" value="Other">
<label for="other">Other</label>
</p>
<p><span><input type="checkbox" required></span> I agree to these <a href= "##">terms and conditions </a></p>
<button type:"button" class="signupbutton">Sign Up</button>
<hr>
<p class="or">OR</p></form>
This is my php code
<?php
$dbhost = 'localhost' ;
$username = 'root' ;
$password = '' ;
$db = 'task';
$fname = filter_input(INPUT_POST,'fname');
$lname = filter_input(INPUT_POST,'lname');
$dataemail = filter_input(INPUT_POST,'fdataemail');
$datapass = filter_input(INPUT_POST,'datapass');
$dob = filter_input(INPUT_POST,'dob');
$gender = filter_input(INPUT_POST,'gender');
$conn =new mysqli("$dbhost", "$username", "$password", "$db" );
echo "Connected to db";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `signup` (`First name`, `Last name`, `Email ID`, `Password`, `Date of Birth`, `Gender`)
VALUES ('$fname','$lname','$dataemail','$datapass','$dob','$gender')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>