The fallacy of the undistributed middle takes the following form:
This can be graphically represented as:
where the premises are in the green box and the conclusion is derived above them.
It may or may not be the case that "all Zs are Bs," but in either case it is irrelevant to the conclusion. What is relevant to the conclusion is whether it is true that "all Bs are Zs," which is ignored in the argument. The fallacy is similar to affirming the consequent and denying the antecedent in that if the terms were swapped around in either the conclusion or the first co-premise, then it would no longer be a fallacy.
The middle term is the one that appears in both premises — in this case, it is the class of backpack carriers. It is undistributed because neither of its uses applies to all backpack carriers. Therefore it can't be used to connect students and my grandfather — both of them could be separate and unconnected divisions of the class of backpack carriers. Note below how "carries a backpack" is truly undistributed:
Specifically, the structure of this example results in affirming the consequent.
However, if the latter two statements were switched, the syllogism would be valid:
In this case, the middle term is the class of students, and the first use clearly refers to 'all students'. It is therefore distributed across the whole of its class, and so can be used to connect the other two terms (backpack carriers, and my grandfather). Again, note below that "student" is distributed: