We don't have your database or even know how it is organised. So only you can find the problem.
Is there an
AID
field in the
assign
table?
Add error checks for each call and report errors.
For debugging you might also report success for each command like
if ($result) {
echo "Found recordset\n";
} else {
echo "Recordset not found\n";
}