抛出else if错误


thorowing error on else if

我已经给出了2个选项(上传图标/选择图标)的形式,但当我用php检查它的抛出错误…

<label class="tagslabel">Upload Icon</label>
<input name="uploadicon" type="file" />
<span>or</span>
<ul class="icons clearfix">
    <li>
        <input type="radio" value="123456" name="selecticon"/>
        <label for="selecticon">
            <img src="pics/123456.jpg" alt="123456" width="34" height="34" />
        </label>
    </li>
    <li>
        <input type="radio" value="654321" name="selecticon" />
        <label for="selecticon">
            <img src="pics/654321.jpg" alt="654321" width="34" height="34" />
        </label>
    </li>
</ul>
php

if (!empty($_FILES['uploadicon']['name'])) {
     //do image processing and validation
}
else {
    if($_POST['selecticon'] == '') $errors['selecticon'] = 'Please Select An Icon or upload Icon!';
}

但它抛出以下错误,如果我上传图像而不是选择一个。

Notice: Undefined index: selecticon

尝试更改

if($_POST['selecticon'] == '')

if (!isset($_POST['selecticon']))

用户可能既没有选择您的选项,也没有自己上传文件。在这种情况下,你应该检查$_POST超全局变量中是否存在'selecticon'。像这样:

 if(!isset($_POST['selecticon'] || $_POST['selecticon'] == '') $errors['selecticon'] = 'Please Select An Icon or upload Icon!'