I am trying to send a first name and last name to my database using a form, but when I try it does not actually send any values to FirstName and LastName, however it does add a new record as an ID is created.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Student Form</title>
</head>
<body>
<form action="insert.php" method="post">
<p>
<label for="FirstName">First Name:</label>
<input type="text" name="FirstName" id="FirstName">
</p>
<p>
<label for="lastName">Last Name:</label>
<input type="text" name="LastName" id="LastName">
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
PHP (as a separate file called 'insert.php'):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Students (FirstName, LastName)
VALUES ('$FirstName', '$LastName')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Any help would be greatly appreciated.