Also, make sure the code is really doing what you want it to.
if ($row[7]) {
// ...
$row[6] = ...;
}
And also ensure that your ifs are nested or not nested as per your requirements. Your indentation suggests the if($row[7]) should be nested within the first if block, but it is not. So either unindent that code, or wrap it all in { }.