I know questions are fine, but most here learn stuff first, and ask a question if they get stuck.
The idea is to at least have put forth an effort at some basics of the subject.
Your error is you are trying to foreach around something that is not iterable. I don't really use mysqli_query at all, so I'm not sure what it returns, but obviously you can't iterate over it.
You should try to debug your script, it might help. I would start by dumping your $result variable to see what you actually have:
var_dump($result);
I searched on google, and you may need something like this:
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
print_r($row);
}