I am creating an HTML form that will take user input, such as first name, and use a PHP file to then post to the MySQL database. HTML code is as follows:
<!DOCTYPE HTML>
<html>
<body>
<form action="contactform.php" method="POST">
<p>First Name: <input type="text" name="F_Name" /></p>
<input type="submit" value="Submit" />
</form>
</body>
</html>
The contactform.php looks like:
<?php
$DB_NAME = "mydbname";
$DB_USER = "mydbuser";
$DB_PASSWORD = "mydbpw";
$DB_HOST = "localhost";
$link = new mysqli($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME);
if ($link->connect_error) {
die('Could not connect: ' . $link->connect_error);
}
$F_Name = $_POST['F_Name'];
$sql = "INSERT INTO myTableName ('F_Name') VALUES ('$F_Name')";
if ($link->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $link->error;
}
$link->close();
?>
After clicking submit (from the HTML code) I receive a 404 error. Any advice on why this may be and how to fix it?
Thanks for your assistance!