PHP for each loop error
<p>I have a loop to go through an array and each <code>checkbox</code> that is selected I want to put the value (also brought in dynamically) into my <code>QuestionSelected</code> table. I get this error <code>"Warning: Invalid argument supplied for foreach()"</code> and I cannot get the results into my table. Here is the code I am trying:</p>

<pre><code>//Declare the QuestionID as a array
$QuestionID = array();


while($row = mysqli_fetch_array($run,MYSQLI_ASSOC)){
echo '&lt;div id="QuestionSelection"&gt;&lt;input id="chkQuestion" type="checkbox" value=" '.$row['QuestionID'].'" name="question_'.$row['QuestionID'].'"&gt;' .$row['Question']. '&lt;/p&gt;&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;';

//Assign the QuestionID from the table to the var
$QuestionID[] = $row['QuestionID'];

}


if($_POST['submitted']) { 


$ids_list = '';

foreach($_POST["QuestionID"] as $id)
{
$ids_list .= (strlen($ids_list) &gt; 0 ? ',' : '').mysql_real_escape_string($id);
}

$sql2 = "INSERT INTO tbl_QuestionSelected (`QuestionID`) VALUES (".$ids_list.")";

}//End of IF 'submitted
</code></pre>
