This question already has an answer here:
I'm still a beginner to php and I cannot seem to understand what's wrong here. The code still works even though there's an 'unidentified index' error. The error I get would be referring to the variables $food, $calories, $healthy, $submit.
The code is:
<?php
require 'connect.inc.php';
$foodname = $_POST['food_name'];
$calories = $_POST['calories'];
$healthy = $_POST['healthy_unhealthy'];
$submit_button = $_POST['submit'];
$sql="INSERT INTO `food` (`food`, `calories`, `healthy_unhealthy`) VALUES('$foodname', '$calories', '$healthy')";
if(isset($submit_button)&&!empty($foodname)&&!empty($calories)&&!empty($healthy))
{
mysql_query($sql, $conn);
}
else{
echo'Kindly fill in fields';
}
?>
<form action="insert.php" method="POST">
Food Name:<br>
<input type="text" name="food_name"><br>
Calories:<br>
<input type="text" name="calories"><br>
Healthy:<br>
<input type="text" name="healthy_unhealthy"><br>
<input type="submit" name="submit">
</form>
</div>