This is the error currently show. Below The first code I save as details.php and the second on as details.html
Warning: Undefined array key "first_name" in C:\xampp\htdocs\children_math\detail2.php on line 12
Warning: Undefined array key "last_name" in C:\xampp\htdocs\children_math\detail2.php on line 13
Warning: Undefined array key "email" in C:\xampp\htdocs\children_math\detail2.php on line 14
Warning: Undefined array key "age" in C:\xampp\htdocs\children_math\detail2.php on line 15
ERROR: Could not able to execute INSERT INTO details (first_name, last_name, email, age) VALUES ('', '', '', ''). Cannot add or update a child row: a foreign key constraint fails (record.details, CONSTRAINT details_ibfk_1 FOREIGN KEY (id) REFERENCES users (id))
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "record");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$first_name = mysqli_real_escape_string($link, $_REQUEST['first_name']);
$last_name = mysqli_real_escape_string($link, $_REQUEST['last_name']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$age = mysqli_real_escape_string($link, $_REQUEST['age']);
// Attempt insert query execution
$sql = "INSERT INTO details (first_name, last_name, email, age) VALUES ('$first_name', '$last_name', '$email', '$age')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Record Form</title>
</head>
<body>
<form action="detail2.php" method="post">
<p>
<label for="firstName">First Name:</label>
<input type="text" name="first_name" id="firstName">
</p>
<p>
<label for="lastName">Last Name:</label>
<input type="text" name="last_name" id="lastName">
</p>
<p>
<label for="emailAddress">Email Address:</label>
<input type="text" name="email" id="emailAddress">
</p>
<p>
<label for="ages">Email Address:</label>
<input type="text" name="age" id="ages">
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>```