You're checking for the presence of $_POST['submit'], and setting some variables if it's found. You're then executing your mysql query outside the conditional block, so if the $_POST variables aren't found you'll get undefined variable errors.
$_POST['submit']
undefined variable
Try