Presuming $id is a numeric value, and looking what you have there, I'd say it's empty or null. How? If it's empty,
..... WHERE id='$id'"
would give you
"UPDATE tablename SET field1='value1' WHERE id=''"
which would not error. But this
"UPDATE tablename SET field1='value1' WHERE id=$id"
would, because you do not have to quote numeric values and is one way to alert you to something like this.
I've I'm ten miles off, $id is all present and accounted for, what does this give you right after your loop?
echo "UPDATE $db SET $st WHERE id=$id"; exit;
Semantically (and more of a guess) I'd say "$db" is a dangerous variable to use for a table, $tblname might be better. It's not uncommon to assign $db to a database name, or a connection, maybe that could be the problem too?