This wont work…
if ($_POST['form'] != '') { // you have no inputs named `form`
Suggest adding a hidden input to your form, and checking for that to see if it was submitted…
<input type="hidden" name="POSTED" value="1">
// then check for submit like this...
if ((isset($_POST['POSTED'])) && ($_POST['POSTED'] ==1)){