php - CodeIgniter inserting data to database with quotes in string -
data like
$data = array ( 'question' => 'how “something” in' 'answer_one' => '1. answer' ... 'correct_answer' => 1 );
i use
$this->db->insert('questions',$data);
when run
$this->db->last_query()
i get:
insert `questions` (`question`, `answer_one`, ... , `correct_answer`) values ('how “something” in', '1. answer', ... ,'1')
and data saved
how ?something? in
and
$data = array ( 'question' => 'my name is…' 'answer_one' => '1. answer' ... 'correct_answer' => 1 );
is run as
insert `questions` (`question`, `answer_one`, ... , `correct_answer`) values ('my name is…', '1. name', ... , '1')
is inserted
"my name is?"
$data = array ( 'question' => 'what's name?' 'answer_one' => '1. answer' ... 'correct_answer' => 1 );
is inserted as
what?s name?
and question table like
create table `questions` ( `question_id` int(11) not null auto_increment, `question` varchar(200), `answer_one` varchar(80), ... `correct_answer` int(2), `created_at` timestamp not null default current_timestamp, primary key (`question_id`) ) engine=innodb auto_increment=1 default charset=utf8;
use htmlentities()
$data = array ( 'question' => htmlentities('how “something” in'), 'answer_one' => '1. answer' ... 'correct_answer' => 1 );
or
use str_replace()
$value = 'how “something” in'; $data = array ( 'question' => str_replace('"', '', $value);, 'answer_one' => '1. answer' 'correct_answer' => 1 );
Comments
Post a Comment