sql server - Issue escaping single quote on mssql 2008 from php codeigniter -
i doing insert database 1 of columns trying escape single quotes user might type. example, it's
, using codeigniter framework , did following escape column:
$test=$this->db->escape($test);
but sql-server error when submit. example if type it's
, trying this
insert table (test) values(''it''s'')
when should be
insert table (test) values('it''s')
why inserting single quotes?
you escaping entire sql statement when should escaping string inserting. example, lets have following code currently.
$test = "insert table (test) values ('" . $value . "');";
you should change be
$test = "insert table (test) values ('" . $this->db->escape($value) . "');";
edit
as liam pointed out, since using codeigniter, may want consider using query binding provide. see url more information: https://ellislab.com/codeigniter/user-guide/database/queries.html
Comments
Post a Comment