Look at my bolded quotes, are these typos?
EDIT: It's not this board's software, tested in my reply.
You need a SPACE before each and, and there's one OR in there without one.
Second, you might consider using some brackets. It's very likely that even if it did run, you wouldn't get the results you expect. Is it clear (to mysql) what result you're selecting? Using just the first volley of conditions,
WHERE first='$searchclass' AND period='$classperiod' OR second='$searchclass'
So if $first='$searchclass' and period='$classperiod' it will return a result. But it will also return a result if that is not true and $second='$searchclass'. Or is it . . . . if first matches AND period or second matches?
These two scenarios are clarified by
1. WHERE first='$searchclass' AND (period='$classperiod' OR second='$searchclass')
Both the first field and the bracketed condition MUST match, designated by AND. In the bracketed set, one or the other can match, but it HAS to be one or the other, plus the first, or the entire statement returns false.
2. WHERE (first='$searchclass' AND period='$classperiod') OR second='$searchclass'
Both of the first two conditions MUST match, or just the third.
This can be further complicated if you wish to have some of these nested within others, like,
((a=1 and b=2) or c=3) OR (d=4 and (e=5 or f=6 or g=7) and h=8)
This cascades throughout your select and would probably be better served by a union or join, but in this case - bracket that baby so it's clear and you get what you expect.