EDIT: MY BAD! I had a stray line screwing it up
$uid = json_encode($uid);
You have uid_$uid in there. Maybe that's your problem.