$folded_id can be null and breaks SQL code

2nd try %)