I've seen a few questions similar to mine but none that use an array loop for both the table columns and values to insert. I'm fairly new to PDO so I'm a bit lost on how to make this work.
I am creating a form where students enter answers to multiple choice questions and their answers are stored in a database. There are 68 questions. Right now I'm hard coding every single column and value like this:
$stmt = $DBH->prepare("INSERT INTO my_table (student, q1, q2, etc...)
VALUES (?, ?, ?, etc...) ");
$stmt->execute(array($student_name, $answer[1], $answer[2], $answer[3],
etc... through $answer[68]));
This works fine but there has to be an easier way to do this without needing to type every single instance. I'd like to be able to loop through the numbers for the table columns (q1, etc. above) as well as the answer variable array. I just have no idea how to approach this.
Even as far as automatically having the correct number of placeholder question marks - is that even possible?