mysql - in_array() expects parameter 2 to be array, null given error -
i have form displays checkbox each engineer in table. when form submitted if engineer's checkbox isn't ticked removed job ($diary_id).
the code @ moment works page briefly displays error before going next page.
in_array() expects parameter 2 array, null given error
the code on form...
$sql = "select * users type = 'engineer' order first_name"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ ?> <div style="width:70px; float:left"> <input type="hidden" name="engineer_on_page[]" value="<? echo $row['id']; ?>"/> <input type="checkbox" name="engineer[]" <? $eng_id= $row['id']; $result2 = mysql_query("select * calls_engineers call_ce = '$diary_id' , engineer_ce = '$eng_id'"); if((mysql_num_rows($result2)) > 0) { echo 'checked="checked"'; ?> value="<? echo $row['id']; ?>" /> <? echo ' '.$row['first_name']; } else { echo "value=".$row['id']." />"; echo ' '.$row['first_name']; } ?> </div> <? } ?>
the mysql remove unselected engineers
foreach($_post['engineer_on_page'] $engineer_id) { $sql = "select * calls_engineers call_ce = '$diary_id' , engineer_ce = '$engineer_id'"; $result = mysql_query($sql)or die(mysql_error()); if(!in_array($engineer_id, $_post['engineer'])){ if(mysql_num_rows($result) > 0){ $sql = "delete calls_engineers engineer_ce = '$engineer_id' , call_ce = '$diary_id'"; $result = mysql_query($sql)or die(mysql_error()); } } }
i have tried initialise $_post['engineer'] array ($_post['engineer'] = array();) before foreach loop stops error, stops page working, no error messages, doesn't work more.
i aware page needs updated mysqli resolve issue before do.
thanks
if 1 engineer checked, value might string, not array.
then, add is_array()
before calling in_array()
:
if(is_array($_post['engineer']) && !in_array($engineer_id, $_post['engineer'])){ // code }
there lot of ways structure that, should idea.
Comments
Post a Comment