The UPDATE will need to be inside the loop as well, and you need some way of distinguishing which row you're updating each time, using the table's primary key or some other unique property (at the moment, every row with amtpaid!=0 will end up containing the exact same values).
You'll also want to use prepared statements precisely because you'll be running the same UPDATE statement over and over again.
Then again, I think the entire thing, from SELECT, to loop, to calculations, to UPDATE statements, could probably be collapsed down into a single UPDATE statement that can be sent to MySQL and have it do all the work. Maybe two if you don't want to get clever with CASE expressions.
UPDATE paytbl SET
amtpaid = 0,
duedate = DATE_ADD(duedate, INTERVAL 1 MONTH),
prevbal = (amtdue - amtpaid) * (CASE WHEN amtpaid < amtdue + prevbal + latechg + secdep + damage + courcost + nsf - hudpay THEN 1 ELSE -1 END),
latechg = latechg + (CASE WHEN amtpaid < amtdue + prevbal + latechg + secdep + damage + courcost + nsf - hudpay THEN 35 ELSE 0 END),
secdep = 0,
damage = 0,
courtcost = 0,
nsf = 0,
hudpay = 0,
comments = ' '
WHERE amtpaid <> 0