It depends on what exactly are you trying to do. Your current code looks okay, though I would rather write:
$totalcats = '1';
if (isset($_POST['category2']) && $_POST['category2'] != 'Please Select One...') {
$totalcats = '2';
}
or:
$totalcats = (isset($_POST['category2']) && $_POST['category2'] != 'Please Select One...') ? '2' : '1';