SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,397
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    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 ).

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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....

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Reading your answer again: there's no way that this student circumvented the system and added an extra space.

  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,075
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    What is your forms method? POST?

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes...it's a POST...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •