How to implement many-to-many relation between three table?
A teacher can teach the same class several times in the same day and many times over years. A student can re-take a class. But, a teacher can only teach 1 class at a time and a student can only take one class at a time. I would add class instance and class enrollment tables as your junction tables. Your initial attempt isn't that far off from this:

1.studentInfo
  studentId(primary key)
  name
  location

2.subjectInfo
  subjectId(primary key)
  subjectName
  totalmarks

3.teacherInfo
  teacherId(primary key)
  teacherName

4.classInstance
  classId(primary key)
  subjectId(foreign key from subjectInfo)
  teacherId(foreign key from teacherInfo)
  year, semester, time, building, room nr, etc

5.classEnrollment
  studentId(foreign key from studentInfo)
  classId(foreign key from classInstance)
  marks
  attendance