Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

query connection problem

$
0
0
i have 2 tables: fooddiary and food
food: FID, Food, Size, Calories
fooddiary: ID, Date, DayTime, FoodName, Calories
 
user is selecting names of food , they are saved in $_SESSION['foodTypes']
i want to get the calories of each food he chose, add them to a total, and then save them as a row in the fooddiary table
the problem is with the first query, its not getting me the calories
i'm having this:


 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean

 

 

 
foreach ($_SESSION['foodTypes'] as $food)
{
 
$cal=0;
$query = "SELECT Calories FROM food where Food=$food";
$result1 = mysqli_query($con, $query);
$row = mysqli_fetch_array($result1);
$cal=(int)$row['Calories'];
$total= $total + (int) $row['Calories'];
 
$sql="";
$sql = "INSERT INTO fooddiary (ID, Date, DayTime, FoodName, Calories)
VALUES ($clid, '$date', 'Breakfast', '$food', $cal)
ON DUPLICATE KEY UPDATE FoodName = '$food', Calories=$cal";
var_dump($sql);
}

Viewing all articles
Browse latest Browse all 13200

Trending Articles