我仍然是 php 的初学者,我似乎无法理解这里出了什么问题。即使存在“未识别的索引”错误,该代码仍然有效。我得到的错误是指变量 $food、$calories、$healthy、$submit。
代码是:
<?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>