Extra space in an insert

Hello!

I run an educational website which has an assessment component. Students submit multiple choice answers and they’re saved in my database (MySQL) to be compared to the correct solutions at a later date. So far I’ve had 12,000 student responses without a hitch. On the last assessment, however, 1 particular student had 4 responses which were marked as incorrect though, her answers in the database seemed to match the correct solutions. After further investigation, I noticed that each of these submitted solutions had an extra space at the end of the entry. This surprised me since the questions were multiple choice questions, and I’m just posting the solutions which I’ve echoed out after getting them from my database; further, none of the other students had this issue. The quick fix was to compare the trimmed solutions using PHP’s trim(), getting rid of any extra database spaces. However, it’s a bit disconcerting for my code to work for everyone, all of the time, except for this one student.

My question then, is whether extra end spaces may be accidentally inserted into databases due to connection issues, or if there’s some other possibility for this odd behavior.

I appreciate that this is a bit of a question without specifics and may be difficult (impossible?) to answer. However, any insights/thoughts would be appreciated.

-Eric

Does your application validate the values before inserting them in the database? Because I think the most probable cause is that this student sent you answers with an extra end space. No idea why or how though (I know how to do it, but don’t know how HE/SHE did it :wink: ).

Thank you for the response! For multiple choice questions, the students are just pre-clicking on choices that I give them: no user defined input…

Reading your answer again: there’s no way that this student circumvented the system and added an extra space. :slight_smile:

What is your forms method? POST?

Yes…it’s a POST…