php - Invalid argument supplied for checkbox -
my site showing warning:
invalid argument supplied foreach() in /admin/insert.php on line 37
i have used php code data insert in mysql database checkbox
how can solve it?
thanks
<table> <tr> <td bgcolor="#ffebc1"> <input type="checkbox" name="e1[]"value="1" > 国語 <input type="checkbox" name="e1[]" value="2" > 算数 <input type="checkbox" name="e1[]" value="3" > 理科 <input type="checkbox" name="e1[]" value="4" > 社会 <input type="checkbox" name="e1[]" value="5" > 英語 </td> </tr> </table>
<?php $ele_school = $_post['e1']; $selected_schoo2 = ""; foreach ($ele_school $ele_school2 ) { $selected_schoo2 .= $ele_school2 . ", "; } $selected_schoo2 = substr($selected_schoo2, 0, -2); $query="insert person(id,login_date,name,selected_schoo) values('$_post[pid]', '$_post[registration]', '$_post[furigana2]', '$selected_schoo2')"; mysql_query($query) or die("not insert".mysql_error()); ?>
there might case data not coming $_post['e1'],
then in case executing foreach blank array, need is
if(isset($ele_school) && $ele_school != null){ foreach($ele_school $ele_school2){ // script } }
Comments
Post a Comment