I've set up a very simple HTML form to post a First Name and Surname into a MySQL database using mysqli, however the form redirects to my php script just fine, and I get no errors, but my data isn't showing in my table. Any clues? I haven't touched this in a while so I was sort of copying some university projects so please correct any mistakes.
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Adam Short</title>
<link href = "style.css" rel = "stylesheet" type = "text/css" media = "screen" />
</head>
<body>
<div id = "wrapper">
<form name="addAthlete" action="submit.php" method="POST">
<label>First Name:</label>
<input type="text" name="firstName" required="required"><br>
<label>Surname:</label>
<input type="text" name="surname" required="required"><br>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
PHP:
<?php
$mysql_host = "***";
$mysql_database = "***";
$mysql_user = "***";
$mysql_password = "***";
con = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$firstName = mysqli_real_escape_string($con, $_POST["firstName"]);
$surname = mysqli_real_escape_string($con, $_POST["surname"]);
$sql = "INSERT INTO Athlete (FirstName, Surname) VALUES
('$firstName','$surname')";
if (!mysqli_query($con, $sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>