";注意:未定义的偏移量:1〃;当“默认值”保留在表单上并提交时


"Notice: Undefined offset: 1" when a Default Value is left on a Form and submitted

当字段"Industry"保留为默认值时,我在提交表单时收到以下PHP错误:

注意:未定义偏移:1

它指向以下代码行:

list($post_industry, $post_market) = explode("|", $_POST['industry']);

我搜索了一些类似的问题,但找不到任何完全符合我需求的东西。我该如何修复上面的代码,以便在选择Industry字段的默认值时不会出现错误。我可以很好地实现这个字段的错误通知("请选择你的行业…"),我只是想摆脱这个PHP错误。

<?php
$options = null;
$volume = null;
$savings = null;
$compensation = null;
$error = null;
$compensation_index = 0.1;
$compensation_minimun = 55;
$factors = array (
 39999.99   =>  100,
 59999.99   =>  90,
 79999.99   =>  80,
 99999.99   =>  75,
124999.99   =>  70,
149999.99   =>  65,
174999.99   =>  62.5,
199999.99   =>  60,
249999.99   =>  50,
299999.99   =>  47.5,
399999.99   =>  45,
499999.99   =>  40,
500000  => 35
);
$industries = array(
            'Food Industry' =>
                array(
                    "Small ticket restaurant (under $10 avg ticket)" =>
                        array(
                                'rate' =>       4,
                                'savings' =>    1.45
                            ),
                    "Medium ticket restaurant ($11-25 avg ticket)" =>
                        array(
                                'rate' =>       3.5,
                                'savings' =>    1.3
                            ),
                    "High ticket restaurant (>$26 avg ticket)" =>
                        array(
                                'rate' =>       3,
                                'savings' =>    1.25
                            )
                    ),
            'Retail' =>
                array(
                    "Small ticket retail (under $10 avg ticket)" =>
                        array(
                                'rate' =>       4,
                                'savings' =>    1.52
                            ),
                    "Medium ticket retail ($11-25 avg ticket)" =>
                        array(
                                'rate' =>       3.5,
                                'savings' =>    1.35
                            ),
                    "High ticket retail (>$26 avg ticket)" =>
                        array(
                                'rate' =>       3,
                                'savings' =>    1.29
                            ),
                    "Convenience Store" =>
                        array(
                                'rate' =>       3.25,
                                'savings' =>    0.75
                            ),
                    "Supermarket" =>
                        array(
                                'rate' =>       3,
                                'savings' =>    1
                            ),
                    "Gas Station" =>
                        array(
                                'rate' =>       2.75,
                                'savings' =>    0.77
                            ),
                    "Physicians/Healthcare" =>
                        array(
                                'rate' =>       2.75,
                                'savings' =>    1.24
                            )
                ),
            'Direct/eCommerce/Service' =>
                array(
                    "B2B (other businesses are your primary customers)" =>
                        array(
                                'rate' =>       3.25,
                                'savings' =>    1.02
                            ),
                    "eCommerce (web-based, on-line shopping cart)" =>
                        array(
                                'rate' =>       3,
                                'savings' =>    1.20
                            ),
                    "Non-B2B Mail or Telephone Order" =>
                        array(
                                'rate' =>       3.25,
                                'savings' =>    1.27
                            ),
 "Non-Profit Organizations" =>
                        array(
                                'rate' =>       3.25,
                                'savings' =>    1.45
                            ),
                    "Service Industry (carpenter, electrician, plumber,     landscaper, etc.)" =>
                        array(
                                'rate' =>       4,
                                'savings' =>    2.01
                            )
                )
        );

 if (isset($_POST['volume']) && isset($_POST['industry'])) {
$volume = str_replace("$", "",$_POST['volume']);
$volume = str_replace(",", "",$volume);
if (is_numeric($volume)) {
    #$volume = $volume * 1;
    foreach($factors AS $factor_range => $factor) {
        if ($volume <= $factor_range) {
            break;
        }
    }
    list($post_industry, $post_market) = explode("|", $_POST['industry']);
} else {
    $error = "Your monthly Visa/MC/Disc Volume needs to be a number";
}
} else {
$_POST['volume'] = "Monthly Credit Card Sales $";
}
$difference = 0;
foreach ($industries AS $industry => $markets) {
$options .= "<option disabled>$industry</option>";
foreach ($markets AS $market => $rates) {
    $selected = "";
    if ($volume) {
        if ($post_industry == $industry) {
            if ($post_market == $market) {
                $rate = $rates['rate'];
                $savings = $rates['savings'];
                $monthly_volume = $volume;
                $savings = $monthly_volume * ($savings/100) * ($factor/100);
                $compensation = $savings * $compensation_index;
                if ($compensation < $compensation_minimun) $compensation =     $compensation_minimun;
                $difference = $savings - $compensation;
                $selected = " selected";
            }
        }
    }
    $options .= "<option value='"$industry|$market'"$selected> -     $market</option>";
}
$options .= "<option disabled></option>";
}
?>

error_reporting(0);把这个修好了。。。