I am trying to add a single record to a database table using codeigniter active records. The original data is parsed from XML and I have tested that the data is stored present and correct in its respective variable names.
The data is passed from the controller to the view like this:
$data['questionId'] = $question['id'];
$data['answerText'] = $question->answer;
$q = $this->mobile_user_model->save_actual_answers($data);
And the model insert function looks like this:
function save_actual_answers($data) {
$insert = array(
'answerText' => $data['answerText'],
'responseId' => $data['responseId'],
'questionId' => $data['questionId']
);
$q = $this->db->insert('actual_answers', $insert);
return $q;
}
The problem I am having is that codeigniter is not automatically adding single quotes to the string value supplied for answerText. When I run the function, I get this error:
Error Number: 1054
Unknown column 'Dan' in 'field list'
INSERT INTO `actual_answers` (`answerText`, `responseId`, `questionId`)
VALUES (Dan, 12, 7)
This tells me that the value for answerText (in this case the value Dan) is trying to be entered into the table by codeigniter without the single quotes. However, if I hardcode the single quotes myself and append them to the answerText data, like so:
'answerText' => "'" . $data['answerText'] . "'"
the query runs successfully, but the single quotes are added with the string into the table, so the record in the database looks like this:
'Dan' 12 7
Has anybody come across this problem before, or am I doing something drastically wrong which I can't see?