I can't understand why mysqli_query
returns true on an operation where one of the fields doesn't exist. I am trying to UPDATE
a field when the field run_id
matches the variable $id
. However, when $id
isn't set, the echo inside the if statement executes. Would really appreciate your thoughts on this phenomenon.
function sumMiles($id,$runnerRow,$weekArray,$cnn){
//Calculate cumulative miles per week for every runner
$weekMiles=0; //total miles per week
foreach($weekArray as $weekday)
{
$weekMiles+=$runnerRow[$weekday];
}
$addMiles = "UPDATE run SET weekly_total = {$weekMiles} WHERE run_id=$id";//add weekly total into the database's run table
if (mysqli_query($cnn,$addMiles)){
echo "Your weekly total has been updated";
return $weekMiles;
}
else {echo "Your weekly total could not be updated";}
}
I am calling this function like so:
$weekMiles = sumMiles($id,$dailyMileage,$weekArray,$cnn);