First rule of debugging; echo out your results to compare with expected.
For this, use this within the post and post the outcome;
echo '<pre style="text-align: left;">';
print_r($_POST);
echo '</pre>';
With that said, I always find it easier to have a function to do the above, which makes it quick to dump an array out for viewing, like this;
function pr_arr($array) {
echo '<pre style="text-align: right; border: solid 1px red; background: white; color: black;">';
print_r($array);
echo '</pre>';
exit;
}
With that function, you simply go;
pr_arr($_POST);
Anyway, sort that out and post results, then we'll move on with bug finding techniques :)