Q:

Undefined variable error using function

I have a PHP code in which i pass a variable to a function.
My code is working file if i use HTML select tag
<span id="opinion">
            <select name="" id="" STYLE="width: 300px"  onchange="get_opinion(this.value)">
                <option value="">[--Select opinion------]</option>
            <?php 
            if(is_array($opinions) && !empty($opinions))
                {
                    foreach($opinions as $opinion)
                    {
                        echo '<option value="'.$opinion->ID.'"';
                        echo '>';
                        echo $opinion->name;
                        echo '</option>';

                    } 
                }                       

                 ?>
                 </select>
            </span>

But i want to display my data with Check Box,
 When i use Check box with that code i face error "Undefined Variable $opinions"

        <?php 
        if(is_array($opinions) && !empty($opinions))
            {
                foreach($opinions as $opinion)
                {

                    echo    '<input type="checkbox" name="vehicle" value="'.$opinion->ID.'"> $opinion->name';
                } 
            }                       

             ?>

        </span>

Update:
i define that variable as
if(isset( $_REQUEST['fileType']))
{$file_type = $_REQUEST['fileType'];}
else {$file_type=0;}

if(isset($file_type) && $file_type!=0)
{
    $opinions = $cont->get_opinions($file_type); } } }

JavaScript
 function get_opinion_methodology(myid)
{
    var id = document.getElementById("file_methodology").value;
    alert(id);
$.ajax({

        type: "GET",
        url: "test1.php",
        data: "fileType="+myid,
        dataType: "text",
        success: function(msg){
        $("#opinion").html(msg);

        }
    });
}

Can you please help me to sort out my problem??

A:

Before if(isset( $_REQUEST['fileType'])) add  $opinions = array();.
This will make sure you have opinions set even if file_type is not.

