php - Invalid argument supplied for foreach() - but script still works -


the suggested questions have not quite covered issue. i'm intrigued answer here, invalid argument supplied foreach! don't quite see how applies in case.

i have following code, work expect; code builds array of email addresses matching id given hidden form posted previous page, finding 'email' column in mysql database.

however, error: invalid argument supplied foreach() on line 50

any appreciated.

function findemail($id) { $mysqli = new mysqli(dbhost,dbuser,dbpass,db); if ($mysqli->connect_errno) {     error_log("cannot connect mysql: " . $mysqli->connect_error);     return false; }  $query = "select email `students` id = '$id'"; $result = $mysqli->query($query); while($row = $result->fetch_array()) {     $rows[] = $row; } $email = ""; foreach($rows $row) {      //this line 50     $email = ($row['email']); } return $email; }  $userid = array(); $useremail = array();  foreach($_post $key => $value) { array_push($userid, $value); array_push($useremail, findemail($value)); } 

the error isn't fatal, can make be... error $rows not defined -- query must returning empty.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -