I have the following code:

if ((isset($_POST['category2'])) && ($_POST['category2'] != 'Please Select One...')){
$totalcats = '2';
}else{
$totalcats = "1";
}

Is this the best way to check if variable has posted and then check if it equals a result to process? I'm trying to clear up all my error checking. So it requires me to give indexes to all variables. Error_Reporting.

Thanks in advance 🙂

    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';
      Write a Reply...