I want to store the results of a questionnaire to a DB. Along with the data for each question I need to store info about who was being assessed and who assessed the person. That would be personIDs.
I'll have about 30 checkboxes per page of which 0 to 20 can be checked. I plan to store the info in a table like this:
AssessorID | CandidateID | AnswerID | Value
I plan to loop through the POST array and generate 0 to 20 records in that table.
The info for AssessorID and CandidateID will be the same per page that means the same for all the 0 to 20 entries I generate.
I have thought of the following two approaches:
a) make a prepared stmt with 4 parameters thus creating redundant data transfer for the two IDs, because they get sent along each pass
$sqla = sprintf('INSERT INTO tbl (AssessorID, CandidateID, AnswerID, Value) VALUES (?,?,?,?)');
b) make a prepared statement that includes the IDs already, making it necessary to escape those before integrating them into the statement like so:
$sqlb = sprintf('INSERT INTO tbl (AssessorID, CandidateID, AnswerID, Value) VALUES (%s,%s,?,?)', $dbConn->real_escape_string($aID), $dbConn->real_escape_string($cID));
b) seems to be more efficient to me. However I have so far avoided the use of mysqli_real_escape_string since the prepared statements are supposed to be the most secure way and now I'm not sure if there is something more to do or to think of. Is that being overly paranoid? And another question: any other flaws in my approach(es)?
any suggestions welcome
Bjom