Undefined Offsets and index problem

    Date: 11/16/06 (PHP Community)    Keywords: php, html

    I keep getting undefined notices. I was going to see if you guys could show me the pro way of writing this code so it won't give me all those notices. I can get the undefined index thing to go away by doing this:

    if (!isset($_REQUEST['DateOfBirth']) or $_REQUEST['DateOfBirth'])
       $_REQUEST['DateOfBirth'] = null;
    I want to know how this should be handled. thanks.

    Notices:
    Notice: Undefined index: DateOfBirth in /var/www/budget.fidelityreserves.com/html/clientbudget.php on line 156

    Notice: Undefined offset: 2 in /var/www/budget.fidelityreserves.com/html/clientbudget.php on line 158

    Notice: Undefined offset: 1 in /var/www/budget.fidelityreserves.com/html/clientbudget.php on line 165

    Notice: Undefined offset: 2 in /var/www/budget.fidelityreserves.com/html/clientbudget.php on line 165

    Code:
    //Remove characters from DateOfBirth and split into array of three numbers
    $date_arr = preg_split('/[\-\/ ]/', $_REQUEST['DateOfBirth']);
    //If last number in array is a date field
    if ( $date_arr[2] > 1900 ) {
            //reorder array with last number first
            $date = $date_arr[0].$date_arr[1].$date_arr[2];
            $_REQUEST['DateOfBirth'] = $date;
    }
    else {
            //else order array with first number first
            $date = $date_arr[1].$date_arr[2].$date_arr[0];
            $_REQUEST['DateOfBirth'] = $date;
    }
    Thanks again ^_^

    Source: http://community.livejournal.com/php/511077.html

« CodeIgniter woe || Sanity check »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home