i have an array foodtype of food, i want to get the corresponding calorie of each type of food in the array
i’m trying this and i get nothing
i tried to echo something just to test if its entering the IF statement … which i realized its not entering!!
thats the code for the button of ‘Calculate Calories’
<input name="Calculate Calories" type="submit" id="Calculate Calories" value="Calculate Calories">
[code]else if (isset($_POST[‘Calculate Calories’]))
{
echo ‘Calories’;
// Create connection
$con=mysqli_connect(“localhost”,“root”,"",“inshapewebsite”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
foreach ($_SESSION[‘foodTypes’] as $food)
{
$query = “SELECT Calories FROM food where Food=$food”;
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result))
{
echo $row[‘Calories’];
$calories=$calories + $row[‘Calories’];
}
}
echo 'The amount of Calories is: ’ . $calories;
}
[/code]