注意:未定义的索引:第48行的C:\ xampp \ htdocs \ ds \ dsearch.php中的dlocation

时间:2017-06-03 07:31:42

标签: php

第一次加载html表单时出现以下错误。一旦我从下拉列表中选择了该选项,它就可以正常工作。

我得到的错误是第一次: 注意:未定义的索引:第48行的C:\ xampp \ htdocs \ ds \ dsearch.php中的dlocation

    <?php
        $queryfilter = "SELECT distinct dlocation FROM desmit";
        $resultfilter = mysql_query($queryfilter);
        $dlocationfilter=$_POST['dlocation'];
        echo $dlocationfilter;
    ?>

     <form name='frmSearch' action='' method='post'>
        <select name="dlocation">
        <option value="All">All </option>
        <?php
        while ($line = mysql_fetch_array($resultfilter, MYSQL_ASSOC)) {
        ?>
        <option value="<?php echo $line['dlocation'];?>"> <?php echo $line['dlocation'];?> </option>

        <?php
        }
        ?>
        </select>

3 个答案:

答案 0 :(得分:2)

我不知道你要做什么但是使用php的isset()函数来获取$ _POST值

<?php
            $queryfilter = "SELECT distinct dlocation FROM desmit";
            $resultfilter = mysql_query($queryfilter);
            $dlocationfilter= isset($_POST['dlocation']) ? $_POST['dlocation'] : '';
            echo $dlocationfilter;
        ?>

答案 1 :(得分:0)

它表示数组索引不存在,因此检查索引存在:

<?php
$queryfilter = "SELECT distinct dlocation FROM desmit";
$resultfilter = mysql_query($queryfilter);
$dlocationfilter=f(isset($_POST['dlocation']) && $_POST['dlocation']) ? $_POST['dlocation'] : null;
echo $dlocationfilter;
?>

<form name='frmSearch' action='' method='post'>
    <select name="dlocation">
        <option value="All">All </option>
        <?php
        while ($line = mysql_fetch_array($resultfilter, MYSQL_ASSOC)) {
            if(isset($line['dlocation']) && $line['dlocation']) {
            ?>
                <option value="<?php echo $line['dlocation'];?>"> <?php echo $line['dlocation'];?> </option>
            <?php
            }

        }
        ?>
    </select>

答案 2 :(得分:-1)

将此行添加到.htaccess以隐藏通知:

php_flag display_errors off